From 37d2f57e53acfa66025f5e19cc01eb0e71f42e65 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Thu, 23 Feb 2023 08:39:47 -0500 Subject: [PATCH] Fix atExit loop atExit clears itself from the WorkerScript before being executed. --- src/Netscript/killWorkerScript.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Netscript/killWorkerScript.ts b/src/Netscript/killWorkerScript.ts index 27814340a..9b1850054 100644 --- a/src/Netscript/killWorkerScript.ts +++ b/src/Netscript/killWorkerScript.ts @@ -66,11 +66,12 @@ function stopAndCleanUpWorkerScript(ws: WorkerScript): void { if (typeof ws.atExit === "function") { try { ws.env.stopFlag = false; - ws.atExit(); + const atExit = ws.atExit; + ws.atExit = undefined; + atExit(); } catch (e: unknown) { handleUnknownError(e, ws, "Error running atExit function.\n\n"); } - ws.atExit = undefined; } ws.env.stopFlag = true; removeWorkerScript(ws);