From 1db2b400d12447ecc3e38cf9811addc348189a08 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Sun, 26 Apr 2020 13:03:48 -0700 Subject: [PATCH] Fixed dispatch loop that can happen on process exit --- microscript/ILibDuktape_ChildProcess.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microscript/ILibDuktape_ChildProcess.c b/microscript/ILibDuktape_ChildProcess.c index 93e63d5..3ec7203 100644 --- a/microscript/ILibDuktape_ChildProcess.c +++ b/microscript/ILibDuktape_ChildProcess.c @@ -34,6 +34,9 @@ typedef struct ILibDuktape_ChildProcess_SubProcess void *subProcess; void *chain; ILibProcessPipe_Process childProcess; +#ifdef WIN32 + int dispatchFlags; +#endif ILibDuktape_readableStream *stdOut; ILibDuktape_readableStream *stdErr; @@ -108,7 +111,7 @@ void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sen if (!ILibMemory_CanaryOK(p)) { return; } #ifdef WIN32 - if (duk_ctx_context_data(p->ctx)->apc_flags == 0) + if (duk_ctx_context_data(p->ctx)->apc_flags == 0 && p->dispatchFlags == 0) { // This method was called with an APC, but this thread was running an unknown alertable method when it was interrupted // So we must unwind the stack, and use a non-apc method to re-dispatch to this thread, becuase we can't risk @@ -118,6 +121,7 @@ void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sen // We had to do the APC first, becuase otherwise child_process.waitExit() will not work, becuase that method is blocking // the event loop thread with an alertable wait object, so APC is the only way to propagate this event p->exitCode = exitCode; + p->dispatchFlags = 1; Duktape_RunOnEventLoop(p->chain, duk_ctx_nonce(p->ctx), p->ctx, ILibDuktape_ChildProcess_SubProcess_ExitHandler_sink1, NULL, p); } #endif