-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix http server connection list when close
PR-URL: #43949 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Feng Yu <F3n67u@outlook.com>
- Loading branch information
1 parent
61cd11a
commit 25ec71d
Showing
3 changed files
with
58 additions
and
5 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
47 changes: 47 additions & 0 deletions
47
test/parallel/test-http-server-connection-list-when-close.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,47 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
|
||
function request(server) { | ||
http.get({ | ||
port: server.address().port, | ||
path: '/', | ||
}, (res) => { | ||
res.resume(); | ||
}); | ||
} | ||
|
||
{ | ||
const server = http.createServer((req, res) => { | ||
// Hack to not remove parser out of server.connectionList | ||
// See `freeParser` in _http_common.js | ||
req.socket.parser.free = common.mustCall(); | ||
req.socket.on('close', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
res.end('ok'); | ||
}).listen(0, common.mustCall(() => { | ||
request(server); | ||
})); | ||
} | ||
|
||
{ | ||
const server = http.createServer((req, res) => { | ||
// See `freeParser` in _http_common.js | ||
const { parser } = req.socket; | ||
parser.free = common.mustCall(() => { | ||
setImmediate(common.mustCall(() => { | ||
parser.close(); | ||
})); | ||
}); | ||
req.socket.on('close', common.mustCall(() => { | ||
setImmediate(common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); | ||
res.end('ok'); | ||
}).listen(0, common.mustCall(() => { | ||
request(server); | ||
})); | ||
} |