mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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:
1 parent
51230f71ff
commit
5b65348fed
2 files changed
+5
-3
No files matched your search
+4
-2
@@ -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
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user