-
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.
Whether and when a socket is destroyed or not after a timeout is up to the user. This leaves an edge case where a socket that has emitted 'timeout' might be re-used from the free pool. Even if destroy is called on the socket, it won't be removed from the freelist until 'close' which can happen several ticks later. Sockets are removed from the free list on the 'close' event. However, there is a delay between calling destroy() and 'close' being emitted. This means that it possible for a socket that has been destroyed to be re-used from the free list, causing unexpected failures. PR-URL: #32000 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
55486bc
commit 1ffa9f3
Showing
8 changed files
with
139 additions
and
24 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
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
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,94 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
{ | ||
// Ensure reuse of successful sockets. | ||
|
||
const agent = new http.Agent({ keepAlive: true }); | ||
|
||
const server = http.createServer((req, res) => { | ||
res.end(); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
let socket; | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
socket = res.socket; | ||
assert(socket); | ||
res.resume(); | ||
socket.on('free', common.mustCall(() => { | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
assert.strictEqual(socket, res.socket); | ||
assert(socket); | ||
agent.destroy(); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
// Ensure that timeouted sockets are not reused. | ||
|
||
const agent = new http.Agent({ keepAlive: true, timeout: 50 }); | ||
|
||
const server = http.createServer((req, res) => { | ||
res.end(); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
const socket = res.socket; | ||
assert(socket); | ||
res.resume(); | ||
socket.on('free', common.mustCall(() => { | ||
socket.on('timeout', common.mustCall(() => { | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
assert.notStrictEqual(socket, res.socket); | ||
assert.strictEqual(socket.destroyed, true); | ||
agent.destroy(); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
// Ensure that destroyed sockets are not reused. | ||
|
||
const agent = new http.Agent({ keepAlive: true }); | ||
|
||
const server = http.createServer((req, res) => { | ||
res.end(); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
let socket; | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
socket = res.socket; | ||
assert(socket); | ||
res.resume(); | ||
socket.on('free', common.mustCall(() => { | ||
socket.destroy(); | ||
http.get({ port: server.address().port, agent }) | ||
.on('response', common.mustCall((res) => { | ||
assert.notStrictEqual(socket, res.socket); | ||
assert(socket); | ||
agent.destroy(); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
})); | ||
} |
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
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