Skip to content

Commit

Permalink
http2: don't send trailers on a closed connection
Browse files Browse the repository at this point in the history
There is a race condition between onStreamCloseResponse(), which
removes the wantTrailers listener, and Http2Stream.close(), which
will invalidate the connection. IE, sendTrailers can be called on
a closed connection which would crash with a:
Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed

PR-URL: #23146
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
edevil authored and danbev committed Oct 3, 2018
1 parent b25e6ab commit 1bfd035
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function tryClose(fd) {
function onStreamTrailers() {
const stream = this[kOwner];
stream[kState].trailersReady = true;
if (stream.destroyed)
if (stream.destroyed || stream.closed)
return;
if (!stream.emit('wantTrailers')) {
// There are no listeners, send empty trailing HEADERS frame and close.
Expand Down

0 comments on commit 1bfd035

Please sign in to comment.