http: reset stream to unconsumed in unconsume()
Reset the underlying socket of an HTTP stream to be marked as unconsume after the HTTP parser no longer owns it. Fixes: https://github.com/nodejs/node/issues/14407 PR-URL: https://github.com/nodejs/node/pull/14410 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
75a19fb379
commit
29353e5a99
@ -527,6 +527,7 @@ class Parser : public AsyncWrap {
|
|||||||
|
|
||||||
stream->set_alloc_cb(parser->prev_alloc_cb_);
|
stream->set_alloc_cb(parser->prev_alloc_cb_);
|
||||||
stream->set_read_cb(parser->prev_read_cb_);
|
stream->set_read_cb(parser->prev_read_cb_);
|
||||||
|
stream->Unconsume();
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->prev_alloc_cb_.clear();
|
parser->prev_alloc_cb_.clear();
|
||||||
|
@ -234,6 +234,11 @@ class StreamBase : public StreamResource {
|
|||||||
consumed_ = true;
|
consumed_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Unconsume() {
|
||||||
|
CHECK_EQ(consumed_, true);
|
||||||
|
consumed_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
template <class Outer>
|
template <class Outer>
|
||||||
inline Outer* Cast() { return static_cast<Outer*>(Cast()); }
|
inline Outer* Cast() { return static_cast<Outer*>(Cast()); }
|
||||||
|
|
||||||
|
29
test/parallel/test-http-upgrade-reconsume-stream.js
Normal file
29
test/parallel/test-http-upgrade-reconsume-stream.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
if (!common.hasCrypto)
|
||||||
|
common.skip('missing crypto');
|
||||||
|
|
||||||
|
const tls = require('tls');
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
// Tests that, after the HTTP parser stopped owning a socket that emits an
|
||||||
|
// 'upgrade' event, another C++ stream can start owning it (e.g. a TLSSocket).
|
||||||
|
|
||||||
|
const server = http.createServer(common.mustNotCall());
|
||||||
|
|
||||||
|
server.on('upgrade', common.mustCall((request, socket, head) => {
|
||||||
|
// This should not crash.
|
||||||
|
new tls.TLSSocket(socket);
|
||||||
|
server.close();
|
||||||
|
socket.destroy();
|
||||||
|
}));
|
||||||
|
|
||||||
|
server.listen(0, common.mustCall(() => {
|
||||||
|
http.get({
|
||||||
|
port: server.address().port,
|
||||||
|
headers: {
|
||||||
|
'Connection': 'Upgrade',
|
||||||
|
'Upgrade': 'websocket'
|
||||||
|
}
|
||||||
|
}).on('error', () => {});
|
||||||
|
}));
|
Loading…
x
Reference in New Issue
Block a user