Skip to content

Commit 16a74ad

Browse files
committed
http2: guard against null stream/req in OnStreamAfterReqFinished
When a stream is destroyed while a synchronous write is in flight from StreamPipe::ProcessData, ReportWritesToJSStreamListener:: OnStreamAfterReqFinished can be called with a null stream_ or a null req_wrap, causing a null pointer dereference. This race becomes more likely with larger HTTP/2 windows (e.g., #38426) because more data is in flight during session teardown. Add early-return guards for both cases to prevent the crash. Refs: #38426 Refs: #56825 Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent d0c68ba commit 16a74ad

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/stream_base.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
752752
void ReportWritesToJSStreamListener::OnStreamAfterReqFinished(
753753
StreamReq* req_wrap, int status) {
754754
StreamBase* stream = static_cast<StreamBase*>(stream_);
755+
if (stream == nullptr) return;
756+
if (req_wrap == nullptr) return;
755757
Environment* env = stream->stream_env();
756758
if (!env->can_call_into_js()) return;
757759
AsyncWrap* async_wrap = req_wrap->GetAsyncWrap();

0 commit comments

Comments
 (0)