| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f7792de commit f1517cc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -563,7 +563,13 @@ function tickOnSocket(req, socket) { | |||
| 563 | 563 | socket.on('close', socketCloseListener); | |
| 564 | 564 | ||
| 565 | 565 | if (req.timeout) { | |
| 566 | - socket.once('timeout', () => req.emit('timeout')); | ||
| 566 | + const emitRequestTimeout = () => req.emit('timeout'); | ||
| 567 | + socket.once('timeout', emitRequestTimeout); | ||
| 568 | + req.once('response', (res) => { | ||
| 569 | + res.once('end', () => { | ||
| 570 | + socket.removeListener('timeout', emitRequestTimeout); | ||
| 571 | + }); | ||
| 572 | + }); | ||
| 567 | 573 | } | |
| 568 | 574 | req.emit('socket', socket); | |
| 569 | 575 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const http = require('http'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const agent = new http.Agent({ keepAlive: true }); | ||
| 7 | + | ||
| 8 | + const server = http.createServer((req, res) => { | ||
| 9 | + res.end(''); | ||
| 10 | + }); | ||
| 11 | + | ||
| 12 | + const options = { | ||
| 13 | + agent, | ||
| 14 | + method: 'GET', | ||
| 15 | + port: undefined, | ||
| 16 | + host: common.localhostIPv4, | ||
| 17 | + path: '/', | ||
| 18 | + timeout: common.platformTimeout(100) | ||
| 19 | + }; | ||
| 20 | + | ||
| 21 | + server.listen(0, options.host, common.mustCall(() => { | ||
| 22 | + options.port = server.address().port; | ||
| 23 | + doRequest(common.mustCall((numListeners) => { | ||
| 24 | + assert.strictEqual(numListeners, 1); | ||
| 25 | + doRequest(common.mustCall((numListeners) => { | ||
| 26 | + assert.strictEqual(numListeners, 1); | ||
| 27 | + server.close(); | ||
| 28 | + agent.destroy(); | ||
| 29 | + })); | ||
| 30 | + })); | ||
| 31 | + })); | ||
| 32 | + | ||
| 33 | + function doRequest(cb) { | ||
| 34 | + http.request(options, common.mustCall((response) => { | ||
| 35 | + const sockets = agent.sockets[`${options.host}:${options.port}:`]; | ||
| 36 | + assert.strictEqual(sockets.length, 1); | ||
| 37 | + const socket = sockets[0]; | ||
| 38 | + const numListeners = socket.listeners('timeout').length; | ||
| 39 | + response.resume(); | ||
| 40 | + response.once('end', common.mustCall(() => { | ||
| 41 | + process.nextTick(cb, numListeners); | ||
| 42 | + })); | ||
| 43 | + })).end(); | ||
| 44 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments