Merge pull request #13255 from overleaf/em-socket-leak-detection

Reintroduce socket leak detection in all services

GitOrigin-RevId: 0a9a1ced0b886dbb267cb46beb5da7d0133d39aa
This commit is contained in:
Eric Mc Sween 2023-05-30 09:25:50 -04:00 committed by Copybot
parent aeadafa61b
commit adfe7abaaf
9 changed files with 12 additions and 1 deletions

View file

@ -84,7 +84,9 @@ const REDACT_REGEX = /^(Authorization|Set-Cookie|Cookie):.*?\r/gim
function redactObject(obj) { function redactObject(obj) {
const result = {} const result = {}
for (const [key, value] of Object.entries(obj)) { for (const [key, value] of Object.entries(obj)) {
if (key === 'headers') { if (value == null) {
result[key] = null
} else if (key === 'headers') {
// remove headers with sensitive information // remove headers with sensitive information
result[key] = flattenHeaders(value).replace( result[key] = flattenHeaders(value).replace(
REDACT_REGEX, REDACT_REGEX,

View file

@ -13,6 +13,8 @@ metrics.initialize('chat')
logger.initialize('chat') logger.initialize('chat')
metrics.open_sockets.monitor() metrics.open_sockets.monitor()
metrics.leaked_sockets.monitor(logger)
export async function createServer() { export async function createServer() {
const app = express() const app = express()

View file

@ -18,6 +18,7 @@ const Path = require('path')
Metrics.open_sockets.monitor(true) Metrics.open_sockets.monitor(true)
Metrics.memory.monitor(logger) Metrics.memory.monitor(logger)
Metrics.leaked_sockets.monitor(logger)
const ProjectPersistenceManager = require('./app/js/ProjectPersistenceManager') const ProjectPersistenceManager = require('./app/js/ProjectPersistenceManager')
const OutputCacheManager = require('./app/js/OutputCacheManager') const OutputCacheManager = require('./app/js/OutputCacheManager')

View file

@ -23,6 +23,7 @@ logger.initialize('docstore')
if (Metrics.event_loop != null) { if (Metrics.event_loop != null) {
Metrics.event_loop.monitor(logger) Metrics.event_loop.monitor(logger)
} }
Metrics.leaked_sockets.monitor(logger)
Metrics.open_sockets.monitor() Metrics.open_sockets.monitor()
const app = express() const app = express()

View file

@ -27,6 +27,7 @@ Metrics.memory.monitor(logger)
if (Metrics.event_loop) { if (Metrics.event_loop) {
Metrics.event_loop.monitor(logger) Metrics.event_loop.monitor(logger)
} }
Metrics.leaked_sockets.monitor(logger)
app.use(function (req, res, next) { app.use(function (req, res, next) {
Metrics.inc('http-request') Metrics.inc('http-request')

View file

@ -29,6 +29,7 @@ logger.initialize('history-v1')
Metrics.open_sockets.monitor() Metrics.open_sockets.monitor()
Metrics.injectMetricsRoute(app) Metrics.injectMetricsRoute(app)
app.use(Metrics.http.monitor(logger)) app.use(Metrics.http.monitor(logger))
Metrics.leaked_sockets.monitor(logger)
// We may have fairly large JSON bodies when receiving large Changes. Clients // We may have fairly large JSON bodies when receiving large Changes. Clients
// may have to handle 413 status codes and try creating files instead of sending // may have to handle 413 status codes and try creating files instead of sending

View file

@ -16,6 +16,7 @@ if (Settings.sentry.dsn) {
Metrics.initialize('project-history') Metrics.initialize('project-history')
Metrics.event_loop.monitor(logger) Metrics.event_loop.monitor(logger)
Metrics.memory.monitor(logger) Metrics.memory.monitor(logger)
Metrics.leaked_sockets.monitor(logger)
Metrics.open_sockets.monitor() Metrics.open_sockets.monitor()
// log updates as truncated strings // log updates as truncated strings

View file

@ -12,6 +12,7 @@ if (Settings.sentry?.dsn != null) {
logger.initializeErrorReporting(Settings.sentry.dsn) logger.initializeErrorReporting(Settings.sentry.dsn)
} }
metrics.memory.monitor(logger) metrics.memory.monitor(logger)
metrics.leaked_sockets.monitor(logger)
metrics.open_sockets.monitor() metrics.open_sockets.monitor()
export const app = express() export const app = express()

View file

@ -34,6 +34,7 @@ http.globalAgent.maxSockets = Settings.limits.httpGlobalAgentMaxSockets
https.globalAgent.maxSockets = Settings.limits.httpsGlobalAgentMaxSockets https.globalAgent.maxSockets = Settings.limits.httpsGlobalAgentMaxSockets
metrics.memory.monitor(logger) metrics.memory.monitor(logger)
metrics.leaked_sockets.monitor(logger)
metrics.open_sockets.monitor() metrics.open_sockets.monitor()
const Server = require('./app/src/infrastructure/Server') const Server = require('./app/src/infrastructure/Server')