Skip to content

Commit 06954ac

Browse files
authored
@tus/server: don't use AbortSignal.any to fix memory leak (#718)
1 parent cb52d7f commit 06954ac

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tus/server": patch
3+
---
4+
5+
Don't use AbortSignal.any to fix memory leak in older Node.js versions and to not break version support.

packages/server/src/lockers/MemoryLocker.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,23 @@ class MemoryLock implements Lock {
5151

5252
async lock(stopSignal: AbortSignal, requestRelease: RequestRelease): Promise<void> {
5353
const abortController = new AbortController()
54+
const onAbort = () => {
55+
abortController.abort()
56+
}
57+
stopSignal.addEventListener('abort', onAbort)
5458

55-
const abortSignal = AbortSignal.any([stopSignal, abortController.signal])
56-
57-
const lock = await Promise.race([
58-
this.waitTimeout(abortSignal),
59-
this.acquireLock(this.id, requestRelease, abortSignal),
60-
])
61-
62-
abortController.abort()
59+
try {
60+
const lock = await Promise.race([
61+
this.waitTimeout(abortController.signal),
62+
this.acquireLock(this.id, requestRelease, abortController.signal),
63+
])
6364

64-
if (!lock) {
65-
throw ERRORS.ERR_LOCK_TIMEOUT
65+
if (!lock) {
66+
throw ERRORS.ERR_LOCK_TIMEOUT
67+
}
68+
} finally {
69+
stopSignal.removeEventListener('abort', onAbort)
70+
abortController.abort()
6671
}
6772
}
6873

0 commit comments

Comments
 (0)