Skip to content

Commit 579527a

Browse files
committed
Fix promiseTimeout to cleanup setTimeout
Clear the timeout when the promise resolves or rejects to prevent the process from hanging due to uncancelled timers.
1 parent 141712f commit 579527a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/util.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ export const promiseTimeout = async <T>(
5353
const timeoutMins = config.timeoutOverrideMins ?? 5
5454
return await new Promise((resolve, reject) => {
5555
datelog('STARTING', msg)
56-
setTimeout(() => reject(new Error(`Timeout: ${msg}`)), 60000 * timeoutMins)
57-
p.then(v => resolve(v)).catch(e => reject(e))
56+
const timeoutId = setTimeout(
57+
() => reject(new Error(`Timeout: ${msg}`)),
58+
60000 * timeoutMins
59+
)
60+
p.then(v => {
61+
clearTimeout(timeoutId)
62+
resolve(v)
63+
}).catch(e => {
64+
clearTimeout(timeoutId)
65+
reject(e)
66+
})
5867
})
5968
}
6069

0 commit comments

Comments
 (0)