Skip to content

Commit

Permalink
core, bugfix: RunMicrotasks will deadlock due to reentry.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Sep 16, 2023
1 parent 37c35ef commit 6daf638
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fibjs/include/Isolate.h
Expand Up @@ -187,6 +187,8 @@ class Isolate : public exlib::linkitem {
std::unordered_map<uint32_t, SandBox*> m_sandboxes;
uint32_t m_sandboxId = 0;

bool m_intask = false;

obj_ptr<HttpClient> m_httpclient;

obj_ptr<Stream_base> m_stdio[3];
Expand Down
6 changes: 5 additions & 1 deletion fibjs/src/base/Isolate.cpp
Expand Up @@ -35,20 +35,24 @@ static int32_t syncRunMicrotasks(Isolate* isolate)
{
JSFiber::EnterJsScope s(NULL, true);

isolate->m_intask = true;
isolate->m_isolate->PerformMicrotaskCheckpoint();
if (isolate->m_isolate->HasPendingBackgroundTasks())
while (v8::platform::PumpMessageLoop(g_default_platform, isolate->m_isolate,
isolate->m_isolate->HasPendingBackgroundTasks()
? v8::platform::MessageLoopBehavior::kWaitForWork
: platform::MessageLoopBehavior::kDoNotWait))
;
isolate->m_intask = false;

return 0;
}

void Isolate::RunMicrotasks()
{
if (RunMicrotaskSize(m_isolate) > 0 || m_isolate->HasPendingBackgroundTasks())
if (!m_intask
&& (RunMicrotaskSize(m_isolate) > 0
|| m_isolate->HasPendingBackgroundTasks()))
syncCall(this, syncRunMicrotasks, this);
}

Expand Down

0 comments on commit 6daf638

Please sign in to comment.