Skip to content

Commit dfc6f4a

Browse files
indutnyrvagg
authored andcommitted
http: fix pipeline regression
Always check that socket still has the parser. It may be destroyed interim, and we may end up with an uncaught exception. Fix: #3508 PR-URL: nodejs-private/node-private#5 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e2b6d45 commit dfc6f4a

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

lib/_http_server.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ function connectionListener(socket) {
372372
}
373373
}
374374

375-
if (socket._paused) {
375+
if (socket._paused && socket.parser) {
376376
// onIncoming paused the socket, we should pause the parser as well
377377
debug('pause parser');
378378
socket.parser.pause();
@@ -411,7 +411,8 @@ function connectionListener(socket) {
411411
// If we previously paused, then start reading again.
412412
if (socket._paused) {
413413
socket._paused = false;
414-
socket.parser.resume();
414+
if (socket.parser)
415+
socket.parser.resume();
415416
socket.resume();
416417
}
417418
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
const net = require('net');
6+
7+
var once = false;
8+
var first = null;
9+
var second = null;
10+
11+
const chunk = new Buffer(1024);
12+
chunk.fill('X');
13+
14+
var size = 0;
15+
16+
var more;
17+
var done;
18+
19+
var server = http.createServer(function(req, res) {
20+
if (!once)
21+
server.close();
22+
once = true;
23+
24+
if (first === null) {
25+
first = res;
26+
return;
27+
}
28+
if (second === null) {
29+
second = res;
30+
res.write(chunk);
31+
} else {
32+
res.end(chunk);
33+
}
34+
size += res.outputSize;
35+
if (size <= req.socket._writableState.highWaterMark) {
36+
more();
37+
return;
38+
}
39+
done();
40+
}).on('upgrade', function(req, socket) {
41+
second.end(chunk, function() {
42+
socket.end();
43+
});
44+
first.end('hello');
45+
}).listen(common.PORT, function() {
46+
var s = net.connect(common.PORT);
47+
more = function() {
48+
s.write('GET / HTTP/1.1\r\n\r\n');
49+
};
50+
done = function() {
51+
s.write('GET / HTTP/1.1\r\n\r\n' +
52+
'GET / HTTP/1.1\r\nConnection: upgrade\r\nUpgrade: ws\r\n\r\naaa');
53+
};
54+
more();
55+
more();
56+
s.resume();
57+
});

0 commit comments

Comments
 (0)