You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('properly handles immediates when FreeEnvironment() is called on a shared event loop',async()=>{constw=newSynchronousWorker({sharedEventLoop: true,sharedMicrotaskQueue: true});setImmediate(()=>{console.log('first immediate')setImmediate(()=>{console.log('second immediate')setImmediate(()=>{console.log('third immediate');});});});awaitw.stop();});
diff --git a/src/env.cc b/src/env.cc
index e775474306..865a012e50 100644
--- a/src/env.cc+++ b/src/env.cc@@ -1405,12 +1405,18 @@ void Environment::CheckImmediate(uv_check_t* handle) {
return;
do {
- MakeCallback(env->isolate(),- env->process_object(),- env->immediate_callback_function(),- 0,- nullptr,- {0, 0}).ToLocalChecked();+ v8::MaybeLocal<v8::Value> value = MakeCallback(env->isolate(),+ env->process_object(),+ env->immediate_callback_function(),+ 0,+ nullptr,+ {0, 0});+ if (!value.IsEmpty()) {+ value.ToLocalChecked();+ }
} while (env->immediate_info()->has_outstanding() && env->can_call_into_js());
Which generates an infinite loop that I fixed in Node.js with the following patch:
diff --git a/lib/internal/timers.js b/lib/internal/timers.js
index a2a1c1e387..d6d4a7af77 100644
--- a/lib/internal/timers.js+++ b/lib/internal/timers.js@@ -447,6 +447,10 @@ function getTimerCallbacks(runNextTicks) {
// the next tick queue above, which means we need to use the previous
// Immediate's _idleNext which is guaranteed to not have been cleared.
if (immediate._destroyed) {
+ if (prevImmediate === undefined) {+ outstandingQueue.head = null;+ return+ }
outstandingQueue.head = immediate = prevImmediate._idleNext;
continue;
}
diff --git a/src/env.cc b/src/env.cc
index e775474306..865a012e50 100644
--- a/src/env.cc+++ b/src/env.cc@@ -1405,12 +1405,18 @@ void Environment::CheckImmediate(uv_check_t* handle) {
return;
do {
- MakeCallback(env->isolate(),- env->process_object(),- env->immediate_callback_function(),- 0,- nullptr,- {0, 0}).ToLocalChecked();+ v8::MaybeLocal<v8::Value> value = MakeCallback(env->isolate(),+ env->process_object(),+ env->immediate_callback_function(),+ 0,+ nullptr,+ {0, 0});+ if (!value.IsEmpty()) {+ value.ToLocalChecked();+ }+ printf("immediate_info()->count(): %d\n", env->immediate_info()->count());+ printf("immediate_info()->ref_count(): %d\n", env->immediate_info()->ref_count());+ printf("has_outstanding: %d\n", env->immediate_info()->has_outstanding());
} while (env->immediate_info()->has_outstanding() && env->can_call_into_js());
if (env->immediate_info()->ref_count() == 0)
Which unfortunately generates an 'illegal access' error with:
Which I fixed by spinning the event loop for as many times as there are setImmediates:
diff --git a/src/binding.cc b/src/binding.cc
index e0ab488..ddd1f1e 100644
--- a/src/binding.cc+++ b/src/binding.cc@@ -300,6 +300,10 @@ void Worker::Stop(bool may_throw) {
try_catch.SetVerbose(true);
SealHandleScope seal_handle_scope(isolate_);
uv_run(GetCurrentEventLoop(isolate_), UV_RUN_NOWAIT);
+ // Needed to avoid an 'illegal access' error thrown by V8+ // This is the max number of immediates in the queue that we support.+ uv_run(GetCurrentEventLoop(isolate_), UV_RUN_NOWAIT);+ uv_run(GetCurrentEventLoop(isolate_), UV_RUN_NOWAIT);
}
if (env_ != nullptr) {
if (!signaled_stop_) {
However the following does not look like a good fix.
Have you got any ideas?
The text was updated successfully, but these errors were encountered:
Generates the following error:
Which I patched in Node.js with:
Which generates an infinite loop that I fixed in Node.js with the following patch:
Which unfortunately generates an
'illegal access'
error with:Which I fixed by spinning the event loop for as many times as there are setImmediates:
However the following does not look like a good fix.
Have you got any ideas?
The text was updated successfully, but these errors were encountered: