From 3db751b65f19892e42d1c320db8694fd082c823d Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Mon, 9 Jul 2018 20:24:53 -0700 Subject: [PATCH] Fix socket count metric leak --- package.json | 2 +- src/io/ioserver.js | 10 ++------- test/io/ioserver.js | 51 --------------------------------------------- 3 files changed, 3 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 87ef2b12..1eeceb10 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.56.2", + "version": "3.56.3", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/io/ioserver.js b/src/io/ioserver.js index f72a6ac6..d7227394 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -218,18 +218,13 @@ class IOServer { Promise.all(promises).then(() => next()); } - metricsEmittingMiddleware(socket, next) { - emitMetrics(socket); - next(); - } - handleConnection(socket) { - // TODO: move out of handleConnection if possible - // see: https://github.com/calzoneman/sync/issues/724 if (!this.checkIPLimit(socket)) { return; } + emitMetrics(socket); + LOGGER.info('Accepted socket from %s', socket.context.ipAddress); counters.add('socket.io:accept', 1); socket.once('disconnect', () => counters.add('socket.io:disconnect', 1)); @@ -257,7 +252,6 @@ class IOServer { io.use(this.cookieParsingMiddleware.bind(this)); io.use(this.ipSessionCookieMiddleware.bind(this)); io.use(this.authUserMiddleware.bind(this)); - io.use(this.metricsEmittingMiddleware.bind(this)); io.on('connection', this.handleConnection.bind(this)); } diff --git a/test/io/ioserver.js b/test/io/ioserver.js index 30e041e5..e343ecb7 100644 --- a/test/io/ioserver.js +++ b/test/io/ioserver.js @@ -69,57 +69,6 @@ describe('IOServer', () => { }); }); - /* - describe('#ipConnectionLimitMiddleware', () => { - beforeEach(() => { - socket.once = (event, callback) => { - socket[`on_${event}`] = callback; - }; - }); - - it('allows IPs before the limit', done => { - server.ipConnectionLimitMiddleware(socket, error => { - if (error) { - throw error; - } - - done(); - }); - }); - - it('rejects IPs at the limit', done => { - server.ipCount.set(socket.context.ipAddress, - require('../../lib/config').get('io.ip-connection-limit')); - server.ipConnectionLimitMiddleware(socket, error => { - assert(error, 'Expected an error to be returned'); - assert.strictEqual(error.message, - 'Too many connections from your IP address'); - done(); - }); - }); - - it('manages the ipCount map correctly', done => { - const ip = socket.context.ipAddress; - - assert(!server.ipCount.has(ip), 'Test precondition failed: ipCount.has(ip)'); - - server.ipConnectionLimitMiddleware(socket, error => { - if (error) { - throw error; - } - - assert.strictEqual(server.ipCount.get(ip), 1); - - socket.on_disconnect(); - - assert.strictEqual(server.ipCount.get(ip), 0); - - done(); - }); - }); - }); - */ - describe('#cookieParsingMiddleware', () => { it('parses cookies', done => { socket.handshake.headers.cookie = 'flavor=chocolate%20chip';