Skip to content

Commit 6da4fe9

Browse files
http2: prevent assertion failure in OnStreamAfterWrite
1 parent 020578f commit 6da4fe9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/node_http2.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,14 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
17661766
Debug(this, "write finished with status %d", status);
17671767

17681768
MaybeNotifyGracefulCloseComplete();
1769-
CHECK(is_write_in_progress());
1769+
// Guard against write callback being invoked when write is not in progress.
1770+
// This can happen with zombie sessions where the underlying socket is closed
1771+
// but the session hasn't been properly notified. Instead of crashing, we
1772+
// silently handle the inconsistent state. (Ref: https://github.com/nodejs/node/issues/61304)
1773+
if (!is_write_in_progress()) {
1774+
Debug(this, "write callback invoked but write not in progress, possible zombie session");
1775+
return;
1776+
}
17701777
set_write_in_progress(false);
17711778

17721779
// Inform all pending writes about their completion.
@@ -2095,11 +2102,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
20952102
if (nread <= 0) {
20962103
if (nread < 0) {
20972104
PassReadErrorToPreviousListener(nread);
2098-
// Socket has encountered an error or EOF. Close the session to prevent
2099-
// zombie state where the session believes the connection is alive but
2100-
// the underlying socket is dead. This prevents assertion failures in
2101-
// subsequent write attempts. (Ref: https://github.com/nodejs/node/issues/61304)
2102-
Close(NGHTTP2_NO_ERROR, true);
21032105
}
21042106
return;
21052107
}

0 commit comments

Comments
 (0)