From 04490561105ec7e1ce9170ed6318377e990916f0 Mon Sep 17 00:00:00 2001 From: Merlijn Vos Date: Thu, 25 Apr 2024 15:01:35 +0200 Subject: [PATCH] @tus/server: add `lockDrainTimeout` option (#603) * @tus/server: add `lockDrainTimeout` option * Add changeset --- .changeset/serious-mangos-wait.md | 5 +++++ packages/server/src/server.ts | 6 +++++- packages/server/src/types.ts | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/serious-mangos-wait.md 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. */