Skip to content

Commit

Permalink
Merge pull request #2981 from briandipalma/fix-memory-leak-issue-2673
Browse files Browse the repository at this point in the history
fix(server): Remove Socket.IO listeners
  • Loading branch information
dignifiedquire authored May 4, 2018
2 parents a6577d9 + af9c84a commit c2bab1c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ install:
# Install Node.js
- ps: Install-Product node $env:nodejs_version

# Install npm compat with node 4
- npm install -g npm@3

# Output our current versions for debugging
- node --version
- npm --version
Expand Down
4 changes: 4 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
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: 2 additions & 2 deletions test/unit/middleware/proxy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ describe('middleware.proxy', () => {
}
var parsedProxyConfig = m.parseProxyConfig(proxy, config)
expect(parsedProxyConfig).to.have.length(1)
expect(parsedProxyConfig[0].proxy.listeners('proxyReq', true)).to.equal(true)
expect(parsedProxyConfig[0].proxy.listeners('proxyRes', true)).to.equal(true)
expect(parsedProxyConfig[0].proxy.listeners('proxyReq')[0]).to.equal(config.proxyReq)
expect(parsedProxyConfig[0].proxy.listeners('proxyRes')[0]).to.equal(config.proxyRes)
})

it('should handle empty proxy config', () => {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ describe('server', () => {
}

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

Expand Down

0 comments on commit c2bab1c

Please sign in to comment.