From de5cc3352af7c16b9d96debb9005b1e1418cca25 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Tue, 19 Sep 2017 19:03:43 -0700 Subject: [PATCH] Fix another bug with prometheus socket.io emtrics --- src/io/ioserver.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/io/ioserver.js b/src/io/ioserver.js index ad60a1a6..9058f864 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -275,6 +275,7 @@ const promSocketDisconnect = new Counter({ }); function emitMetrics(sock) { try { + let closed = false; let transportName = sock.client.conn.transport.name; promSocketCount.inc({ transport: transportName }); promSocketAccept.inc(1, new Date()); @@ -282,7 +283,7 @@ function emitMetrics(sock) { sock.client.conn.on('upgrade', newTransport => { try { // Sanity check - if (newTransport.name !== transportName) { + if (!closed && newTransport.name !== transportName) { promSocketCount.dec({ transport: transportName }); transportName = newTransport.name; promSocketCount.inc({ transport: transportName }); @@ -295,6 +296,7 @@ function emitMetrics(sock) { sock.once('disconnect', () => { try { + closed = true; promSocketCount.dec({ transport: transportName }); promSocketDisconnect.inc(1, new Date()); } catch (error) {