From 83dffaedddad80c655d152f9db22ac0c3dbdf7b4 Mon Sep 17 00:00:00 2001 From: Stojan Dimitrovski Date: Mon, 27 Oct 2025 18:45:21 +0100 Subject: [PATCH] feat: steal the auth lock if it was not completed in 10s (#39868) --- packages/common/gotrue.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/common/gotrue.ts b/packages/common/gotrue.ts index 0d1db5f69a2..7a241cf4ce1 100644 --- a/packages/common/gotrue.ts +++ b/packages/common/gotrue.ts @@ -144,10 +144,32 @@ async function debuggableNavigatorLock( } console.error( - `Waited for over 10s to acquire an Auth client lock`, + `Waited for over 10s to acquire an Auth client lock, will steal the lock to unblock`, await navigator.locks.query(), stackException ) + + // quickly steal the lock and release it so that others can acquire it, + // while leaving the code that was holding it to continue running + navigator.locks + .request( + name, + { + steal: true, + }, + async () => { + await new Promise((accept) => { + setTimeout(accept, 0) + }) + + console.error('Lock was stolen and now released', stackException) + } + ) + .catch((e: any) => { + if (captureException) { + captureException(e) + } + }) })() }, 10000)