Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
src: no SetImmediate from destructor in stream_pipe code
Guard against running `SetImmediate()` from the destructor.
The object will not be alive or usable in the callback,
so it does not make sense to attempt to schedule the
`SetImmediate()`.
  • Loading branch information
addaleax committed Nov 26, 2019
commit 2286fc0b0f4214fcdb8b40e5f4e5aaa194102b47
6 changes: 4 additions & 2 deletions src/stream_pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ StreamPipe::StreamPipe(StreamBase* source,
}

StreamPipe::~StreamPipe() {
Unpipe();
Unpipe(true);
}

StreamBase* StreamPipe::source() {
Expand All @@ -53,7 +53,7 @@ StreamBase* StreamPipe::sink() {
return static_cast<StreamBase*>(writable_listener_.stream());
}

void StreamPipe::Unpipe() {
void StreamPipe::Unpipe(bool is_in_deletion) {
if (is_closed_)
return;

Expand All @@ -68,6 +68,8 @@ void StreamPipe::Unpipe() {
source()->RemoveStreamListener(&readable_listener_);
sink()->RemoveStreamListener(&writable_listener_);

if (is_in_deletion) return;

// Delay the JS-facing part with SetImmediate, because this might be from
// inside the garbage collector, so we can’t run JS here.
HandleScope handle_scope(env()->isolate());
Expand Down
2 changes: 1 addition & 1 deletion src/stream_pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StreamPipe : public AsyncWrap {
StreamPipe(StreamBase* source, StreamBase* sink, v8::Local<v8::Object> obj);
~StreamPipe() override;

void Unpipe();
void Unpipe(bool is_in_deletion = false);

static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down