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: https://github.com/nodejs/node/pull/32301
PR-URL: https://github.com/nodejs/node/pull/30666
Fixes: https://github.com/nodejs/node/issues/30643
Refs: https://github.com/nodejs/node/pull/30374
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen authored and Myles Borins committed 2020-04-01 17:36:50 -04:00
1 parent 51230f71ff
commit 5b65348fed
2 files changed
+5 -3

No files matched your search

+4 -2
View File
@@ -42,7 +42,7 @@ StreamPipe::StreamPipe(StreamBase* source,
}
StreamPipe::~StreamPipe() {
Unpipe();
Unpipe(true);
}
StreamBase* StreamPipe::source() {
@@ -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;
@@ -69,6 +69,8 @@ void StreamPipe::Unpipe() {
if (pending_writes_ == 0)
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());
+1 -1
View File
@@ -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);