Skip to content

Commit 5b65348

Browse files
addaleaxMylesBorins
authored andcommitted
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()`. Backport-PR-URL: #32301 PR-URL: #30666Fixes: #30643 Refs: #30374 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 51230f7 commit 5b65348

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

‎src/stream_pipe.cc‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ StreamPipe::StreamPipe(StreamBase* source,
4242
}
4343

4444
StreamPipe::~StreamPipe(){
45-
Unpipe();
45+
Unpipe(true);
4646
}
4747

4848
StreamBase* StreamPipe::source(){
@@ -53,7 +53,7 @@ StreamBase* StreamPipe::sink(){
5353
returnstatic_cast<StreamBase*>(writable_listener_.stream());
5454
}
5555

56-
voidStreamPipe::Unpipe(){
56+
voidStreamPipe::Unpipe(bool is_in_deletion){
5757
if (is_closed_)
5858
return;
5959

@@ -69,6 +69,8 @@ void StreamPipe::Unpipe(){
6969
if (pending_writes_ == 0)
7070
sink()->RemoveStreamListener(&writable_listener_);
7171

72+
if (is_in_deletion) return;
73+
7274
// Delay the JS-facing part with SetImmediate, because this might be from
7375
// inside the garbage collector, so we can’t run JS here.
7476
HandleScope handle_scope(env()->isolate());

‎src/stream_pipe.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class StreamPipe : public AsyncWrap{
1212
StreamPipe(StreamBase* source, StreamBase* sink, v8::Local<v8::Object> obj);
1313
~StreamPipe() override;
1414

15-
voidUnpipe();
15+
voidUnpipe(bool is_in_deletion = false);
1616

1717
staticvoidNew(const v8::FunctionCallbackInfo<v8::Value>& args);
1818
staticvoidStart(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
(0)