-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: detach socket from IncomingMessage on keep-alive
If the socket is not detached then a future call to res.destroy (through e.g. pipeline) would unecessarily kill the socket while its in the agent free list. PR-URL: #32153 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/parallel/test-http-client-abort-keep-alive-destroy-res.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
let socketsCreated = 0; | ||
|
||
class Agent extends http.Agent { | ||
createConnection(options, oncreate) { | ||
const socket = super.createConnection(options, oncreate); | ||
socketsCreated++; | ||
return socket; | ||
} | ||
} | ||
|
||
const server = http.createServer((req, res) => res.end()); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const agent = new Agent({ | ||
keepAlive: true, | ||
maxSockets: 1 | ||
}); | ||
|
||
const req = http.get({ agent, port }, common.mustCall((res) => { | ||
res.resume(); | ||
res.on('end', () => { | ||
res.destroy(); | ||
|
||
http.get({ agent, port }, common.mustCall((res) => { | ||
res.resume(); | ||
assert.strictEqual(socketsCreated, 1); | ||
agent.destroy(); | ||
server.close(); | ||
})); | ||
}); | ||
})); | ||
req.end(); | ||
})); |