Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use more reliable close event #1880

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- 10.x
- 12.x
- 14.x
- 16.x
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/bodyReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function bodyReader(options) {
// add 'close and 'aborted' event handlers so that requests (and their
// corresponding memory) don't leak if client stops sending data half
// way through a POST request
req.once('close', next);
req.socket.once('close', next);
req.once('aborted', next);
req.resume();
}
Expand Down
10 changes: 6 additions & 4 deletions test/plugins/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,21 @@ describe('static resource plugin', function() {
directory: TMP_PATH
});

var socket = new net.Socket();
SERVER.get('/index.html', function(req, res, next) {
// closed before serve
serve(req, res, function(nextRoute) {
assert.strictEqual(nextRoute, false);
done();
socket.on('end', () => {
serve(req, res, function(nextRoute) {
assert.strictEqual(nextRoute, false);
done();
});
});
});
SERVER.on('after', function(req, res, route, afterErr) {
assert(afterErr.name, 'RequestCloseError');
done();
});

var socket = new net.Socket();
socket.connect({ host: '127.0.0.1', port: PORT }, function() {
socket.write(RAW_REQUEST, 'utf-8', function(err2, data) {
assert.ifError(err2);
Expand Down