Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8371a8

Browse filesBrowse files
indutnyrvagg
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: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 777eb00 commit d8371a8
Copy full SHA for d8371a8

File tree

Expand file treeCollapse file tree

2 files changed

+29
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-3
lines changed
Open diff view settings
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+5-3Lines changed: 5 additions & 3 deletions
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;
Collapse file
+24Lines changed: 24 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.