Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bb91834
http: move utcDate to internal/http.js
jasnell Oct 17, 2016
c6472e7
tls: add tlsSocket.disableRenegotiation()
jasnell Nov 4, 2016
a22543c
deps: add nghttp2 dependency
jasnell Jul 17, 2017
ea75860
http2: introducing HTTP/2
jasnell Jul 17, 2017
837dfe4
http2: add tests and benchmarks
jasnell Jul 17, 2017
e4b9149
http2: remove redundant return in test
jasnell Jul 17, 2017
8357bd0
http2: fix documentation nits
jasnell Jul 17, 2017
295e4b1
doc: include http2.md in all.md
jasnell Jul 17, 2017
9cb0611
test: fix flakiness in test-http2-client-upload
jasnell Jul 18, 2017
fefe2cb
test: fix flaky test-http2-client-unescaped-path on osx
jasnell Jul 18, 2017
a93b3b8
http2: fix abort when client.destroy inside end event
jasnell Jul 19, 2017
2289352
http2: refinement and test for socketError
jasnell Jul 19, 2017
d74da3a
http2: fix socketOnTimeout and a segfault
jasnell Jul 19, 2017
07758c8
http2: add range support for respondWith{File|FD}
jasnell Jul 22, 2017
0d8bf4c
http2: doc and fixes to the Compatibility API
mcollina Jul 24, 2017
2db82e0
http2: make writeHead behave like HTTP/1.
mcollina Jul 24, 2017
6bc7cc2
http2: address initial pr feedback
jasnell Jul 31, 2017
0a5fe92
http2: refactor trailers API
jasnell Jul 31, 2017
7c5825b
http2: get trailers working with the compat api
jasnell Jul 31, 2017
0e13eb6
http2: use static allocated arrays
jasnell Aug 1, 2017
a2045e9
http2: minor cleanup
jasnell Aug 1, 2017
c9c9e92
http2: fix documentation errors
jasnell Aug 1, 2017
ea2a35f
http2: add some doc detail for invalid header chars
jasnell Aug 1, 2017
69a0783
http2: fix compilation error after V8 update
jasnell Aug 3, 2017
ba2744e
http2: fix linting after rebase
jasnell Aug 3, 2017
c58115d
http2: fix flakiness in timeout
jasnell Aug 3, 2017
79e14a9
http2: rename some nghttp2 stream flags
kjin Aug 5, 2017
38f55ea
test: add crypto check to http2 tests
danbev Aug 7, 2017
ede1161
doc: fix http2 sample code for http2.md
kakts Aug 7, 2017
ea3c8c7
doc: explain browser support of http/2 without SSL
giltayar Aug 7, 2017
e344b91
src,http2: DRY header/trailer handling code up
addaleax Aug 8, 2017
70f7c54
test: increase http2 coverage
michaalbert Aug 8, 2017
1129943
http2: improve perf of passing headers to C++
addaleax Aug 9, 2017
5db4971
src: remove unused http2_socket_buffer from env
addaleax Aug 10, 2017
a6c1571
http2: use per-environment buffers
addaleax Aug 10, 2017
01bada5
http2: name padding buffer fields
addaleax Aug 10, 2017
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: fix abort when client.destroy inside end event
PR-URL: #14239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell committed Aug 13, 2017
commit a93b3b8a4af078dda4845f8d83cbe9544ac05813
68 changes: 35 additions & 33 deletions lib/internal/http2/core.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ function onSessionRead(nread, buf, handle) {
_unrefActive(this); // Reset the session timeout timer
_unrefActive(stream); // Reset the stream timeout timer

if (nread >= 0) {
if (nread >= 0 && !stream.destroyed) {
if (!stream.push(buf)) {
assert(this.streamReadStop(id) === undefined,
`HTTP/2 Stream ${id} does not exist. Please report this as ' +
'a bug in Node.js`);
this.streamReadStop(id);
state.reading = false;
}
} else {
Expand Down Expand Up @@ -1475,44 +1473,48 @@ class Http2Stream extends Duplex {
this.once('ready', this._destroy.bind(this, err, callback));
return;
}
debug(`[${sessionName(session[kType])}] destroying stream ${this[kID]}`);

// Submit RST-STREAM frame if one hasn't been sent already and the
// stream hasn't closed normally...
if (!this[kState].rst) {
const code =
err instanceof Error ?
NGHTTP2_INTERNAL_ERROR : NGHTTP2_NO_ERROR;
this[kSession].rstStream(this, code);
}

process.nextTick(() => {
debug(`[${sessionName(session[kType])}] destroying stream ${this[kID]}`);

// Submit RST-STREAM frame if one hasn't been sent already and the
// stream hasn't closed normally...
if (!this[kState].rst && !session.destroyed) {
const code =
err instanceof Error ?
NGHTTP2_INTERNAL_ERROR : NGHTTP2_NO_ERROR;
this[kSession].rstStream(this, code);
}

// Remove the close handler on the session
session.removeListener('close', this[kState].closeHandler);
// Remove the close handler on the session
session.removeListener('close', this[kState].closeHandler);

// Unenroll the timer
unenroll(this);
// Unenroll the timer
unenroll(this);

setImmediate(finishStreamDestroy.bind(this, handle));
session[kState].streams.delete(this[kID]);
delete this[kSession];
setImmediate(finishStreamDestroy.bind(this, handle));

// All done
const rst = this[kState].rst;
const code = rst ? this[kState].rstCode : NGHTTP2_NO_ERROR;
if (code !== NGHTTP2_NO_ERROR) {
const err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
process.nextTick(() => this.emit('error', err));
}
process.nextTick(emit.bind(this, 'streamClosed', code));
debug(`[${sessionName(session[kType])}] stream ${this[kID]} destroyed`);
callback(err);
// All done
const rst = this[kState].rst;
const code = rst ? this[kState].rstCode : NGHTTP2_NO_ERROR;
if (code !== NGHTTP2_NO_ERROR) {
const err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
process.nextTick(() => this.emit('error', err));
}
process.nextTick(emit.bind(this, 'streamClosed', code));
debug(`[${sessionName(session[kType])}] stream ${this[kID]} destroyed`);
callback(err);
});
}
}

function finishStreamDestroy(handle) {
const id = this[kID];
const session = this[kSession];
session[kState].streams.delete(id);
delete this[kSession];
if (handle !== undefined)
handle.destroyStream(this[kID]);
handle.destroyStream(id);
this.emit('destroy');
}

function processHeaders(headers) {
Expand Down
Empty file modified src/node_http2.cc
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions src/node_http2.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class Http2Session : public AsyncWrap,
padding_strategy_ = opts.GetPaddingStrategy();

Init(env->event_loop(), type, *opts);
stream_buf_.AllocateSufficientStorage(kAllocBufferSize);
}

~Http2Session() override {
Expand Down Expand Up @@ -456,15 +455,16 @@ class Http2Session : public AsyncWrap,
}

char* stream_alloc() {
return *stream_buf_;
return stream_buf_;
}

private:
StreamBase* stream_;
StreamResource::Callback<StreamResource::AllocCb> prev_alloc_cb_;
StreamResource::Callback<StreamResource::ReadCb> prev_read_cb_;
padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
MaybeStackBuffer<char, kAllocBufferSize> stream_buf_;

char stream_buf_[kAllocBufferSize];
};

class ExternalHeader :
Expand Down
7 changes: 2 additions & 5 deletions src/node_http2_core-inl.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ inline int Nghttp2Session::Free() {
Nghttp2Session* session =
ContainerOf(&Nghttp2Session::prep_,
reinterpret_cast<uv_prepare_t*>(handle));

session->OnFreeSession();
DEBUG_HTTP2("Nghttp2Session %d: session is free\n",
session->session_type_);
};
uv_close(reinterpret_cast<uv_handle_t*>(&prep_), PrepClose);

Expand Down Expand Up @@ -302,9 +299,9 @@ inline void Nghttp2Stream::ResetState(
inline void Nghttp2Stream::Destroy() {
DEBUG_HTTP2("Nghttp2Stream %d: destroying stream\n", id_);
// Do nothing if this stream instance is already destroyed
if (IsDestroyed() || IsDestroying())
if (IsDestroyed())
return;
flags_ |= NGHTTP2_STREAM_DESTROYING;
flags_ |= NGHTTP2_STREAM_DESTROYED;
Nghttp2Session* session = this->session_;

if (session != nullptr) {
Expand Down
8 changes: 1 addition & 7 deletions src/node_http2_core.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ enum nghttp2_stream_flags {
// Stream is closed
NGHTTP2_STREAM_CLOSED = 0x8,
// Stream is destroyed
NGHTTP2_STREAM_DESTROYED = 0x10,
// Stream is being destroyed
NGHTTP2_STREAM_DESTROYING = 0x20
NGHTTP2_STREAM_DESTROYED = 0x10
};


Expand Down Expand Up @@ -290,10 +288,6 @@ class Nghttp2Stream {
return (flags_ & NGHTTP2_STREAM_DESTROYED) == NGHTTP2_STREAM_DESTROYED;
}

inline bool IsDestroying() const {
return (flags_ & NGHTTP2_STREAM_DESTROYING) == NGHTTP2_STREAM_DESTROYING;
}

// Queue outbound chunks of data to be sent on this stream
inline int Write(
nghttp2_stream_write_t* req,
Expand Down
17 changes: 11 additions & 6 deletions test/parallel/test-http2-options-max-reserved-streams.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ server.on('listening', common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`,
options);

let remaining = 2;
function maybeClose() {
if (--remaining === 0) {
server.close();
client.destroy();
}
}

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

// Because maxReservedRemoteStream is 1, the stream event
Expand All @@ -59,15 +67,12 @@ server.on('listening', common.mustCall(() => {
client.on('stream', common.mustCall((stream) => {
stream.resume();
stream.on('end', common.mustCall());
stream.on('streamClosed', common.mustCall(maybeClose));
}));

req.on('response', common.mustCall());

req.resume();
req.on('end', common.mustCall(() => {
server.close();
client.destroy();
}));
req.end();

req.on('end', common.mustCall());
req.on('streamClosed', common.mustCall(maybeClose));
}));
3 changes: 2 additions & 1 deletion test/parallel/test-http2-response-splitting.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(headers.location, undefined);
}));
req.resume();
req.on('end', common.mustCall(maybeClose));
req.on('end', common.mustCall());
req.on('streamClosed', common.mustCall(maybeClose));
}

doTest(str, 'location', str);
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-http2-server-socket-destroy.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function onStream(stream) {

assert.notStrictEqual(stream.session, undefined);
socket.destroy();
assert.strictEqual(stream.session, undefined);
stream.on('destroy', common.mustCall(() => {
assert.strictEqual(stream.session, undefined);
}));
}

server.listen(0);
Expand All @@ -49,9 +51,8 @@ server.on('listening', common.mustCall(() => {
[HTTP2_HEADER_METHOD]: HTTP2_METHOD_POST });

req.on('aborted', common.mustCall());
req.resume();
req.on('end', common.mustCall());
req.on('response', common.mustCall());
req.on('data', common.mustCall());

client.on('close', common.mustCall());
}));