Skip to content

Commit e19d110

Browse files
authored
fix(utils): clear repeatingTask anySignal per run (#3401)
* fix(utils): clear repeatingTask anySignal per run --------- Co-authored-by: lodekeeper <lodekeeper@users.noreply.github.com>
1 parent 464e16e commit e19d110

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/utils/src/repeating-task.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
7777
signal: shutdownController.signal
7878
}
7979

80+
let signal: ReturnType<typeof anySignal> | undefined
81+
8082
if (options?.timeout != null) {
81-
const signal = anySignal([shutdownController.signal, AbortSignal.timeout(options.timeout)])
83+
signal = anySignal([shutdownController.signal, AbortSignal.timeout(options.timeout)])
8284
setMaxListeners(Infinity, signal)
8385

8486
opts.signal = signal
@@ -91,6 +93,17 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
9193
})
9294
.catch(() => {})
9395
.finally(() => {
96+
if (signal != null) {
97+
if (signal.aborted) {
98+
signal.clear()
99+
} else {
100+
// Clear listeners once this per-run signal eventually aborts
101+
signal.addEventListener('abort', () => {
102+
signal.clear()
103+
}, { once: true })
104+
}
105+
}
106+
94107
running = false
95108

96109
if (shutdownController.signal.aborted) {

0 commit comments

Comments
 (0)