Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
819ff1a
deps: cherry-pick 46c4979e86 from upstream v8
bnoordhuis Feb 21, 2018
62dc43d
src: clean up process.dlopen()
bnoordhuis Feb 22, 2018
86fa308
src: make process.dlopen() load well-known symbol
bnoordhuis Feb 22, 2018
6bd8c10
build: fix gocvr version used for coverage
mhdawson Mar 2, 2018
a3b9542
module: fix cyclical dynamic import
bmeck Feb 23, 2018
57ddfd1
doc: add simple example to rename function
punteek Feb 16, 2018
6ad9be0
doc: new team for bundlers or delivery of Node.js
mhdawson Mar 2, 2018
dc25929
deps: cherry-pick 0bcb1d6f from upstream V8
jakobkummerow Dec 5, 2017
d268061
doc: add introduced_in metadata to _toc.md
Trott Mar 4, 2018
15281b0
doc: update cc list
BridgeAR Mar 2, 2018
83c912a
doc: remove tentativeness in pull-requests.md
Trott Mar 4, 2018
7861df9
doc: remove subsystem from pull request template
Trott Mar 4, 2018
d6153e9
src: refactor GetPeerCertificate
danbev Mar 2, 2018
0b22bab
src: use std::unique_ptr for STACK_OF(X509)
bnoordhuis Mar 2, 2018
7448712
test: move require http2 to after crypto check
danbev Mar 3, 2018
4829469
src: #include <stdio.h>" to iculslocs
srl295 Mar 5, 2018
c89e8f3
perf_hooks: fix timing
TimothyGu Feb 25, 2018
c81a391
test: add more information to assert.strictEqual
ryzokuken Mar 6, 2018
03784d7
src: handle exceptions in env->SetImmediates
jasnell Jan 26, 2018
6e1bed1
src: prevent persistent handle resource leaks
bnoordhuis Feb 21, 2018
5b4eeb8
src: remove unnecessary Reset() calls
bnoordhuis Feb 21, 2018
d3eaf77
src: don't touch js object in Http2Session dtor
bnoordhuis Feb 21, 2018
4e9ac10
http2: no stream destroy while its data is on the wire
addaleax Feb 26, 2018
23807d7
net: inline and simplify onSocketEnd
addaleax Feb 6, 2018
64746c7
stream: add no-half-open enforcer only if needed
lpinca Feb 23, 2018
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
Prev Previous commit
Next Next commit
http2: no stream destroy while its data is on the wire
This fixes a crash that occurred when a `Http2Stream` write
is completed after it is already destroyed.

Instead, don’t destroy the stream in that case and wait for
GC to take over.

Backport-PR-URL: #19185
PR-URL: #19002
Fixes: #18973
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
addaleax authored and MylesBorins committed Mar 6, 2018
commit 4e9ac109b49d84167db5aed8deb504856fbfeac8
20 changes: 15 additions & 5 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,14 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
stream_buf_ = uv_buf_init(nullptr, 0);
}

bool Http2Session::HasWritesOnSocketForStream(Http2Stream* stream) {
for (const nghttp2_stream_write& wr : outgoing_buffers_) {
if (wr.req_wrap != nullptr && wr.req_wrap->stream() == stream)
return true;
}
return false;
}

// Every Http2Session session is tightly bound to a single i/o StreamBase
// (typically a net.Socket or tls.TLSSocket). The lifecycle of the two is
// tightly coupled with all data transfer between the two happening at the
Expand Down Expand Up @@ -1753,13 +1761,11 @@ Http2Stream::Http2Stream(


Http2Stream::~Http2Stream() {
DEBUG_HTTP2STREAM(this, "tearing down stream");
if (session_ != nullptr) {
session_->RemoveStream(this);
session_ = nullptr;
}

if (!object().IsEmpty())
ClearWrap(object());
}

// Notify the Http2Stream that a new block of HEADERS is being processed.
Expand Down Expand Up @@ -1837,15 +1843,19 @@ inline void Http2Stream::Destroy() {
Http2Stream* stream = static_cast<Http2Stream*>(data);
// Free any remaining outgoing data chunks here. This should be done
// here because it's possible for destroy to have been called while
// we still have qeueued outbound writes.
// we still have queued outbound writes.
while (!stream->queue_.empty()) {
nghttp2_stream_write& head = stream->queue_.front();
if (head.req_wrap != nullptr)
head.req_wrap->Done(UV_ECANCELED);
stream->queue_.pop();
}

delete stream;
// We can destroy the stream now if there are no writes for it
// already on the socket. Otherwise, we'll wait for the garbage collector
// to take care of cleaning up.
if (!stream->session()->HasWritesOnSocketForStream(stream))
delete stream;
}, this, this->object());

statistics_.end_time = uv_hrtime();
Expand Down
3 changes: 3 additions & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,9 @@ class Http2Session : public AsyncWrap, public StreamListener {
// Removes a stream instance from this session
inline void RemoveStream(Http2Stream* stream);

// Indicates whether there currently exist outgoing buffers for this stream.
bool HasWritesOnSocketForStream(Http2Stream* stream);

// Write data to the session
inline ssize_t Write(const uv_buf_t* bufs, size_t nbufs);

Expand Down
62 changes: 62 additions & 0 deletions test/parallel/test-http2-write-finishes-after-stream-destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Flags: --expose-gc
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const makeDuplexPair = require('../common/duplexpair');

// Make sure the Http2Stream destructor works, since we don't clean the
// stream up like we would otherwise do.
process.on('exit', global.gc);

{
const { clientSide, serverSide } = makeDuplexPair();

let serverSideHttp2Stream;
let serverSideHttp2StreamDestroyed = false;
const server = http2.createServer();
server.on('stream', common.mustCall((stream, headers) => {
serverSideHttp2Stream = stream;
stream.respond({
'content-type': 'text/html',
':status': 200
});

const originalWrite = serverSide._write;
serverSide._write = (buf, enc, cb) => {
if (serverSideHttp2StreamDestroyed) {
serverSide.destroy();
serverSide.write = () => {};
} else {
setImmediate(() => {
originalWrite.call(serverSide, buf, enc, () => setImmediate(cb));
});
}
};

// Enough data to fit into a single *session* window,
// not enough data to fit into a single *stream* window.
stream.write(Buffer.alloc(40000));
}));

server.emit('connection', serverSide);

const client = http2.connect('http://localhost:80', {
createConnection: common.mustCall(() => clientSide)
});

const req = client.request({ ':path': '/' });

req.on('response', common.mustCall((headers) => {
assert.strictEqual(headers[':status'], 200);
}));

req.on('data', common.mustCallAtLeast(() => {
if (!serverSideHttp2StreamDestroyed) {
serverSideHttp2Stream.destroy();
serverSideHttp2StreamDestroyed = true;
}
}));
}