diff options
author | Karl Böhlmark <karl.bohlmark@netinsight.se> | 2016-11-01 16:59:31 +0100 |
---|---|---|
committer | Italo A. Casas <me@italoacasas.com> | 2016-12-08 16:05:22 -0500 |
commit | 9a5d47542d2e9e2874188251dc670d14929fe6f3 (patch) | |
tree | 676966696c5aa16fd82df699fc91e1086920025b /test/parallel/test-http-client-timeout-option-listeners.js | |
parent | 6dd07545ff504c8349a24c936dbf0ecde3c66238 (diff) | |
download | android-node-v8-9a5d47542d2e9e2874188251dc670d14929fe6f3.tar.gz android-node-v8-9a5d47542d2e9e2874188251dc670d14929fe6f3.tar.bz2 android-node-v8-9a5d47542d2e9e2874188251dc670d14929fe6f3.zip |
http: remove stale timeout listeners
In order to prevent a memory leak when using keep alive, ensure that the
timeout listener for the request is removed when the response has ended.
PR-URL: https://github.com/nodejs/node/pull/9440
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-http-client-timeout-option-listeners.js')
-rw-r--r-- | test/parallel/test-http-client-timeout-option-listeners.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-http-client-timeout-option-listeners.js b/test/parallel/test-http-client-timeout-option-listeners.js new file mode 100644 index 0000000000..3ac6cd4616 --- /dev/null +++ b/test/parallel/test-http-client-timeout-option-listeners.js @@ -0,0 +1,44 @@ +'use strict'; +const common = require('../common'); +const http = require('http'); +const assert = require('assert'); + +const agent = new http.Agent({ keepAlive: true }); + +const server = http.createServer((req, res) => { + res.end(''); +}); + +const options = { + agent, + method: 'GET', + port: undefined, + host: common.localhostIPv4, + path: '/', + timeout: common.platformTimeout(100) +}; + +server.listen(0, options.host, common.mustCall(() => { + options.port = server.address().port; + doRequest(common.mustCall((numListeners) => { + assert.strictEqual(numListeners, 1); + doRequest(common.mustCall((numListeners) => { + assert.strictEqual(numListeners, 1); + server.close(); + agent.destroy(); + })); + })); +})); + +function doRequest(cb) { + http.request(options, common.mustCall((response) => { + const sockets = agent.sockets[`${options.host}:${options.port}:`]; + assert.strictEqual(sockets.length, 1); + const socket = sockets[0]; + const numListeners = socket.listeners('timeout').length; + response.resume(); + response.once('end', common.mustCall(() => { + process.nextTick(cb, numListeners); + })); + })).end(); +} |