From adfe7abaaf8a971c5412c10eb0f1ac58df9fc0b1 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween <5454374+emcsween@users.noreply.github.com> Date: Tue, 30 May 2023 09:25:50 -0400 Subject: [PATCH] Merge pull request #13255 from overleaf/em-socket-leak-detection Reintroduce socket leak detection in all services GitOrigin-RevId: 0a9a1ced0b886dbb267cb46beb5da7d0133d39aa --- libraries/metrics/leaked_sockets.js | 4 +++- services/chat/app/js/server.js | 2 ++ services/clsi/app.js | 1 + services/docstore/app.js | 1 + services/filestore/app.js | 1 + services/history-v1/app.js | 1 + services/project-history/app/js/server.js | 1 + services/spelling/app/js/server.js | 1 + services/web/app.js | 1 + 9 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/metrics/leaked_sockets.js b/libraries/metrics/leaked_sockets.js index 8f27513a88..3720b4af24 100644 --- a/libraries/metrics/leaked_sockets.js +++ b/libraries/metrics/leaked_sockets.js @@ -84,7 +84,9 @@ const REDACT_REGEX = /^(Authorization|Set-Cookie|Cookie):.*?\r/gim function redactObject(obj) { const result = {} 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 result[key] = flattenHeaders(value).replace( REDACT_REGEX, diff --git a/services/chat/app/js/server.js b/services/chat/app/js/server.js index 28f7b6f1b6..f388ab3336 100644 --- a/services/chat/app/js/server.js +++ b/services/chat/app/js/server.js @@ -13,6 +13,8 @@ metrics.initialize('chat') logger.initialize('chat') metrics.open_sockets.monitor() +metrics.leaked_sockets.monitor(logger) + export async function createServer() { const app = express() diff --git a/services/clsi/app.js b/services/clsi/app.js index 44e1e5c4d4..b9a70316f0 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -18,6 +18,7 @@ const Path = require('path') Metrics.open_sockets.monitor(true) Metrics.memory.monitor(logger) +Metrics.leaked_sockets.monitor(logger) const ProjectPersistenceManager = require('./app/js/ProjectPersistenceManager') const OutputCacheManager = require('./app/js/OutputCacheManager') diff --git a/services/docstore/app.js b/services/docstore/app.js index f8e83fb4ec..1fb11d3589 100644 --- a/services/docstore/app.js +++ b/services/docstore/app.js @@ -23,6 +23,7 @@ logger.initialize('docstore') if (Metrics.event_loop != null) { Metrics.event_loop.monitor(logger) } +Metrics.leaked_sockets.monitor(logger) Metrics.open_sockets.monitor() const app = express() diff --git a/services/filestore/app.js b/services/filestore/app.js index a0406fac1c..807c86bcea 100644 --- a/services/filestore/app.js +++ b/services/filestore/app.js @@ -27,6 +27,7 @@ Metrics.memory.monitor(logger) if (Metrics.event_loop) { Metrics.event_loop.monitor(logger) } +Metrics.leaked_sockets.monitor(logger) app.use(function (req, res, next) { Metrics.inc('http-request') diff --git a/services/history-v1/app.js b/services/history-v1/app.js index 9f1033c041..391551f632 100644 --- a/services/history-v1/app.js +++ b/services/history-v1/app.js @@ -29,6 +29,7 @@ logger.initialize('history-v1') Metrics.open_sockets.monitor() Metrics.injectMetricsRoute(app) app.use(Metrics.http.monitor(logger)) +Metrics.leaked_sockets.monitor(logger) // 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 diff --git a/services/project-history/app/js/server.js b/services/project-history/app/js/server.js index d7b83975a4..c583f55927 100644 --- a/services/project-history/app/js/server.js +++ b/services/project-history/app/js/server.js @@ -16,6 +16,7 @@ if (Settings.sentry.dsn) { Metrics.initialize('project-history') Metrics.event_loop.monitor(logger) Metrics.memory.monitor(logger) +Metrics.leaked_sockets.monitor(logger) Metrics.open_sockets.monitor() // log updates as truncated strings diff --git a/services/spelling/app/js/server.js b/services/spelling/app/js/server.js index 50ac2420d1..ba5ba8e0e8 100644 --- a/services/spelling/app/js/server.js +++ b/services/spelling/app/js/server.js @@ -12,6 +12,7 @@ if (Settings.sentry?.dsn != null) { logger.initializeErrorReporting(Settings.sentry.dsn) } metrics.memory.monitor(logger) +metrics.leaked_sockets.monitor(logger) metrics.open_sockets.monitor() export const app = express() diff --git a/services/web/app.js b/services/web/app.js index 28068c90bb..148f9df730 100644 --- a/services/web/app.js +++ b/services/web/app.js @@ -34,6 +34,7 @@ http.globalAgent.maxSockets = Settings.limits.httpGlobalAgentMaxSockets https.globalAgent.maxSockets = Settings.limits.httpsGlobalAgentMaxSockets metrics.memory.monitor(logger) +metrics.leaked_sockets.monitor(logger) metrics.open_sockets.monitor() const Server = require('./app/src/infrastructure/Server')