Skip to content

Commit

Permalink
catch teardown rejection and exit (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapaezbas authored Dec 13, 2024
1 parent cfd2dce commit 0181836
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ 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
resolve()
}, 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 {
Expand Down

0 comments on commit 0181836

Please sign in to comment.