http2: fix onread assert when destroying session from stream handler by sankalpsthakur · Pull Request #65116 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion lib/internal/http2/core.js
10 changes: 10 additions & 0 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,16 @@ int Http2Session::OnBeginHeadersCallback(nghttp2_session* handle,
// The common case is that we're creating a new stream. The less likely
// case is that we're receiving a set of trailers
if (!stream) [[likely]] {
// Close() may be deferred while mem_recv is in progress (see
// Http2Session::Close). A 'stream' handler that calls session.destroy()
// runs via nextTick from MakeCallback during that window, so later
// HEADERS in the same receive buffer must not create a C++ stream
// whose JS wrapper (and onread) is never installed.
if (session->is_closing()) {
nghttp2_submit_rst_stream(
session->session(), NGHTTP2_FLAG_NONE, id, NGHTTP2_REFUSED_STREAM);
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
}
if (!session->CanAddStream() ||
Http2Stream::New(session, id, frame->headers.cat) == nullptr)
[[unlikely]] {
Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-http2-session-destroy-stream-handler.js
Loading