From 0181836ec8d0dfa3b65eba1c9e3a091524f30eb2 Mon Sep 17 00:00:00 2001 From: rafapaezbas <15270736+rafapaezbas@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:21:46 +0100 Subject: [PATCH] catch teardown rejection and exit (#494) --- lib/api.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/api.js b/lib/api.js index 6e413a8a1..75f77609e 100644 --- a/lib/api.js +++ b/lib/api.js @@ -59,6 +59,7 @@ class API { const MAX_TEARDOWN_WAIT = 15000 let timeout = null let timedout = false + let rejected = null const countdown = new Promise((resolve) => { timeout = setTimeout(() => { timedout = true @@ -66,9 +67,12 @@ class API { }, MAX_TEARDOWN_WAIT) }) this.#teardowns.finally(() => { clearTimeout(timeout) }) - await Promise.race([this.#teardowns, countdown]) - if (timedout) { - console.error(`Max teardown wait reached after ${MAX_TEARDOWN_WAIT} ms. Exiting...`) + await Promise.race([this.#teardowns, countdown]).catch((err) => { + rejected = err + }) + if (timedout || rejected !== null) { + if (timeout) console.error(`Max teardown wait reached after ${MAX_TEARDOWN_WAIT} ms. Exiting...`) + if (rejected) console.error(`${rejected}. User teardown threw. Exiting...`) if (global.Bare) { Bare.exit() } else {