-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: check for handle before running asyncReset()
If an uninitialized or user supplied Socket is in the freeSockets list of the Agent it would automatically attempt to run ._handle.asyncReset(), but would throw from those not existing. Guard against that by first checking that they exist. PR-URL: #14419 Fixes: #13539 Refs: #13352 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
- Loading branch information
1 parent
142ce5c
commit 751e873
Showing
3 changed files
with
61 additions
and
3 deletions.
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
30 changes: 30 additions & 0 deletions
30
test/parallel/test-http-agent-uninitialized-with-handle.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,30 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
const agent = new http.Agent({ | ||
keepAlive: true, | ||
}); | ||
const socket = new net.Socket(); | ||
// If _handle exists then internals assume a couple methods exist. | ||
socket._handle = { | ||
ref() { }, | ||
readStart() { }, | ||
}; | ||
const req = new http.ClientRequest(`http://localhost:${common.PORT}/`); | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.end(); | ||
})).listen(common.PORT, common.mustCall(() => { | ||
// Manually add the socket without a _handle. | ||
agent.freeSockets[agent.getName(req)] = [socket]; | ||
// Now force the agent to use the socket and check that _handle exists before | ||
// calling asyncReset(). | ||
agent.addRequest(req, {}); | ||
req.on('response', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
req.end(); | ||
})); |
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,25 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
const agent = new http.Agent({ | ||
keepAlive: true, | ||
}); | ||
const socket = new net.Socket(); | ||
const req = new http.ClientRequest(`http://localhost:${common.PORT}/`); | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.end(); | ||
})).listen(common.PORT, common.mustCall(() => { | ||
// Manually add the socket without a _handle. | ||
agent.freeSockets[agent.getName(req)] = [socket]; | ||
// Now force the agent to use the socket and check that _handle exists before | ||
// calling asyncReset(). | ||
agent.addRequest(req, {}); | ||
req.on('response', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
req.end(); | ||
})); |