diff --git a/.changeset/serious-mangos-wait.md b/.changeset/serious-mangos-wait.md new file mode 100644 index 00000000..0fccde4c --- /dev/null +++ b/.changeset/serious-mangos-wait.md @@ -0,0 +1,5 @@ +--- +'@tus/server': minor +--- + +Add `lockDrainTimeout` option diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index 04694571..7e54322c 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -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 @@ -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) diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index 5dac6040..08c5767d 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -71,6 +71,11 @@ export type ServerOptions = { | Promise | ((req: http.IncomingMessage) => Locker | Promise) + /** + * This timeout controls how long the server will wait a cancelled lock to do its cleanup. + */ + lockDrainTimeout?: number + /** * Disallow termination for finished uploads. */