Fix another bug with prometheus socket.io emtrics

This commit is contained in:
Calvin Montgomery 2017-09-19 19:03:43 -07:00
parent 9a1d50dcd3
commit de5cc3352a
1 changed files with 3 additions and 1 deletions

View File

@ -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) {