File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
packages/clerk-js/src/core/auth Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,16 @@ import { createWorkerTimers } from '@clerk/shared/workerTimers';
3
3
import { SafeLock } from './safeLock' ;
4
4
5
5
const REFRESH_SESSION_TOKEN_LOCK_KEY = 'clerk.lock.refreshSessionToken' ;
6
- const INTERVAL_IN_MS = 5 * 1_000 ;
6
+
7
+ /**
8
+ * Returns an interval in milliseconds with random jitter.
9
+ * Uses a base interval of 5 seconds and adds up to 1.5 seconds of random jitter.
10
+ * This randomization helps prevent synchronized polling requests across multiple clients.
11
+ */
12
+ const getIntervalInMs = ( ) => {
13
+ const jitter = Math . random ( ) * 1500 ;
14
+ return 5 * 1_000 + jitter ;
15
+ } ;
7
16
8
17
export class SessionCookiePoller {
9
18
private lock = SafeLock ( REFRESH_SESSION_TOKEN_LOCK_KEY ) ;
@@ -20,7 +29,7 @@ export class SessionCookiePoller {
20
29
const run = async ( ) => {
21
30
this . initiated = true ;
22
31
await this . lock . acquireLockAndRun ( cb ) ;
23
- this . timerId = this . workerTimers . setTimeout ( run , INTERVAL_IN_MS ) ;
32
+ this . timerId = this . workerTimers . setTimeout ( run , getIntervalInMs ( ) ) ;
24
33
} ;
25
34
26
35
void run ( ) ;
You can’t perform that action at this time.
0 commit comments