Skip to content

Commit

Permalink
fix(server): Remove Socket.IO listeners
Browse files Browse the repository at this point in the history
Not removing Socket.IO listeners can cause memory issues
in long running processes that spawn many Karma instance.

Fixes #2980
  • Loading branch information
briandipalma committed May 3, 2018
1 parent a6577d9 commit c3f05ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/server.js
Expand Up @@ -425,6 +425,10 @@ Server.prototype._start = function (config, launcher, preprocess, fileList,
}

self.emitAsync('exit').then(function () {
// Remove Socket.IO listeners. `connection` callback closes over `Server`
// instance so it leaks Plugin state e.g. Webpack compilations.
socketServer.sockets.removeAllListeners()
socketServer.close()
// don't wait forever on webServer.close() because
// pending client connections prevent it from closing.
var closeTimeout = setTimeout(removeAllListeners, webServerCloseTimeout)
Expand Down
4 changes: 3 additions & 1 deletion test/unit/server.spec.js
Expand Up @@ -65,13 +65,15 @@ describe('server', () => {
}

mockSocketServer = {
close: () => {},
flashPolicyServer: {
close: () => {}
},
sockets: {
sockets: {},
on: () => {},
emit: () => {}
emit: () => {},
removeAllListeners: () => {}
}
}

Expand Down

0 comments on commit c3f05ef

Please sign in to comment.