Skip to content

Commit ea15d71

Browse files
indutnyFishrock123
authored andcommitted
http_server: fix resume after socket close
Socket resume may happen on a next tick, and in following scenario: 1. `socket.resume()` 2. `socket._handle.close()` 3. `socket._handle = null;` The `_resume` will be invoked with empty `._handle` property. There is nothing bad about it, and we should just ignore the `resume`/`pause` events in this case. Same applies to the unconsuming of socket on adding `data` and/or `readable` event listeners. Fix: #2821 PR-URL: #2824 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent ed47ab6 commit ea15d71

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/_http_server.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,13 @@ function connectionListener(socket) {
512512
exports._connectionListener = connectionListener;
513513

514514
function onSocketResume() {
515-
this._handle.readStart();
515+
if (this._handle)
516+
this._handle.readStart();
516517
}
517518

518519
function onSocketPause() {
519-
this._handle.readStop();
520+
if (this._handle)
521+
this._handle.readStop();
520522
}
521523

522524
function socketOnWrap(ev, fn) {
@@ -526,7 +528,7 @@ function socketOnWrap(ev, fn) {
526528
return res;
527529
}
528530

529-
if (ev === 'data' || ev === 'readable')
531+
if (this._handle && (ev === 'data' || ev === 'readable'))
530532
this.parser.unconsume(this._handle._externalStream);
531533

532534
return res;
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
const server = http.createServer(function(req, res) {
7+
res.writeHead(200);
8+
res.end();
9+
10+
server.close();
11+
});
12+
13+
server.listen(common.PORT, function() {
14+
15+
const req = http.request({
16+
method: 'POST',
17+
port: common.PORT
18+
});
19+
20+
const payload = new Buffer(16390);
21+
payload.fill('Й');
22+
req.write(payload);
23+
req.end();
24+
});

0 commit comments

Comments
 (0)