Skip to content

Commit

Permalink
@tus/server: add lockDrainTimeout option (#603)
Browse files Browse the repository at this point in the history
* @tus/server: add `lockDrainTimeout` option

* Add changeset
  • Loading branch information
Murderlon authored Apr 25, 2024
1 parent 7f0c368 commit 0449056
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/serious-mangos-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tus/server': minor
---

Add `lockDrainTimeout` option
6 changes: 5 additions & 1 deletion packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export class Server extends EventEmitter {
options.locker = new MemoryLocker()
}

if (!options.lockDrainTimeout) {
options.lockDrainTimeout = 3000
}

const {datastore, ...rest} = options
this.options = rest as ServerOptions
this.datastore = datastore
Expand Down Expand Up @@ -288,7 +292,7 @@ export class Server extends EventEmitter {
abortWithDelayController.signal.removeEventListener('abort', onDelayedAbort)
setTimeout(() => {
requestAbortController.abort(err)
}, 3000)
}, this.options.lockDrainTimeout)
}
abortWithDelayController.signal.addEventListener('abort', onDelayedAbort)

Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export type ServerOptions = {
| Promise<Locker>
| ((req: http.IncomingMessage) => Locker | Promise<Locker>)

/**
* This timeout controls how long the server will wait a cancelled lock to do its cleanup.
*/
lockDrainTimeout?: number

/**
* Disallow termination for finished uploads.
*/
Expand Down

0 comments on commit 0449056

Please sign in to comment.