From 8fe62f8d3854f3e89f90c63b15c837b48c3c7311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Fri, 28 Sep 2018 15:07:11 +0100 Subject: [PATCH] http2: don't send trailers on a closed connection 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: https://github.com/nodejs/node/pull/23146 Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/internal/http2/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 28acc533410d3f..ce659dfc3de131 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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.