Skip to content

Commit 0449056

Browse files
authored
@tus/server: add lockDrainTimeout option (#603)
* @tus/server: add `lockDrainTimeout` option * Add changeset
1 parent 7f0c368 commit 0449056

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/serious-mangos-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tus/server': minor
3+
---
4+
5+
Add `lockDrainTimeout` option

packages/server/src/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export class Server extends EventEmitter {
9292
options.locker = new MemoryLocker()
9393
}
9494

95+
if (!options.lockDrainTimeout) {
96+
options.lockDrainTimeout = 3000
97+
}
98+
9599
const {datastore, ...rest} = options
96100
this.options = rest as ServerOptions
97101
this.datastore = datastore
@@ -288,7 +292,7 @@ export class Server extends EventEmitter {
288292
abortWithDelayController.signal.removeEventListener('abort', onDelayedAbort)
289293
setTimeout(() => {
290294
requestAbortController.abort(err)
291-
}, 3000)
295+
}, this.options.lockDrainTimeout)
292296
}
293297
abortWithDelayController.signal.addEventListener('abort', onDelayedAbort)
294298

packages/server/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ export type ServerOptions = {
7171
| Promise<Locker>
7272
| ((req: http.IncomingMessage) => Locker | Promise<Locker>)
7373

74+
/**
75+
* This timeout controls how long the server will wait a cancelled lock to do its cleanup.
76+
*/
77+
lockDrainTimeout?: number
78+
7479
/**
7580
* Disallow termination for finished uploads.
7681
*/

0 commit comments

Comments
 (0)