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
16 changes: 11 additions & 5 deletions src/stream_pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void StreamPipe::Unpipe(bool is_in_deletion) {

is_closed_ = true;
is_reading_ = false;
source()->RemoveStreamListener(&readable_listener_);
// Source may already be gone here during destroy
if (source() != nullptr) source()->RemoveStreamListener(&readable_listener_);
if (pending_writes_ == 0 || sink_destroyed_)
sink()->RemoveStreamListener(&writable_listener_);

Expand Down Expand Up @@ -209,8 +210,14 @@ void StreamPipe::WritableListener::OnStreamAfterShutdown(ShutdownWrap* w,
void StreamPipe::ReadableListener::OnStreamDestroy() {
StreamPipe* pipe = ContainerOf(&StreamPipe::readable_listener_, this);
pipe->source_destroyed_ = true;
if (!pipe->is_eof_) {
OnStreamRead(UV_EPIPE, uv_buf_init(nullptr, 0));
if (pipe->is_eof_) return;

// Mirror ReadableListener::OnStreamRead() teardown, but without
// other stream interactions:
pipe->is_eof_ = true;
if (pipe->pending_writes_ == 0) {
pipe->sink()->Shutdown();
pipe->Unpipe();
}
}

Expand All @@ -227,8 +234,7 @@ void StreamPipe::WritableListener::OnStreamDestroy() {
void StreamPipe::WritableListener::OnStreamWantsWrite(size_t suggested_size) {
StreamPipe* pipe = ContainerOf(&StreamPipe::writable_listener_, this);
pipe->wanted_data_ = suggested_size;
if (pipe->is_reading_ || pipe->is_closed_)
return;
if (pipe->is_reading_ || pipe->is_closed_ || pipe->source_destroyed_) return;
HandleScope handle_scope(pipe->env()->isolate());
InternalCallbackScope callback_scope(pipe,
InternalCallbackScope::kSkipTaskQueues);
Expand Down
8 changes: 5 additions & 3 deletions test/parallel/test-stream-pipeline-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const http2 = require('http2');
client.close();
}));

let cnt = 10;
let received = 0;
req.on('data', (data) => {
cnt--;
if (cnt === 0) rs.destroy();
received += data.length;
// Bound the data that flows before teardown - bytes per data event vary
// by platform, and letting this run longer hangs on macOS.
if (received >= 32 * 1024) rs.destroy();
});
}));
}
Loading