Skip to content

Commit 83dffae

Browse files
authored
feat: steal the auth lock if it was not completed in 10s (supabase#39868)
1 parent 482e477 commit 83dffae

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/common/gotrue.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,32 @@ async function debuggableNavigatorLock<R>(
144144
}
145145

146146
console.error(
147-
`Waited for over 10s to acquire an Auth client lock`,
147+
`Waited for over 10s to acquire an Auth client lock, will steal the lock to unblock`,
148148
await navigator.locks.query(),
149149
stackException
150150
)
151+
152+
// quickly steal the lock and release it so that others can acquire it,
153+
// while leaving the code that was holding it to continue running
154+
navigator.locks
155+
.request(
156+
name,
157+
{
158+
steal: true,
159+
},
160+
async () => {
161+
await new Promise((accept) => {
162+
setTimeout(accept, 0)
163+
})
164+
165+
console.error('Lock was stolen and now released', stackException)
166+
}
167+
)
168+
.catch((e: any) => {
169+
if (captureException) {
170+
captureException(e)
171+
}
172+
})
151173
})()
152174
}, 10000)
153175

0 commit comments

Comments
 (0)