Session token cache drops every token when the device clock runs fast, so the poller mints a token every 1.5 s (fast-clock side of #10401)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #10583 de @umeraamir69 — cerrado sin fusionar
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, typescript
- Área
- authentication, frontend
Línea de trabajo
The bug sits in the session token cache, where expiresAt is computed as Math.min(l.exp, n.createdAt + l.exp - l.iat), and in startPollingForSessionToken, which calls session.getToken() every 1500 ms or 5000 ms. Reproduce by overriding Date.now to add about 200 s and watching for repeated POST …/tokens calls. Done means a freshly minted token stays cached under a fast clock, but the issue leaves the fix approach open, so confirm the direction with maintainers first; the linked PR #10583 was closed without merging.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Packages
@clerk/clerk-js6.42.1 (latest; same in 6.42.2-canary.v20261102095039). Same effect in 6.41.0, 6.7.5 and 6.3.3.- Loaded via
@clerk/vue2.0.7 and@clerk/react6.14.x (CDN@clerk/clerk-js@6), and bundled directly.
What happens
When the device clock runs about a minute or more fast, clerk-js discards every session token as soon as it is cached. Every getToken() call and every poller tick then goes to POST /v1/client/sessions/{id}/tokens.
Measured with one focused tab and the clock 200 s ahead: 43 token POSTs in 71 s, versus one every ~44 s with a correct clock. With about ten tabs open the Frontend API answers 429, getToken() keeps retrying (up to 8 times online, ~160 s), and anything that waits for a token stalls.
This is not theoretical: within four days we saw two production clients whose clocks were +198 s and +224 s off (one after a laptop battery had run completely flat).
Reproduction
- Sign in to any app that uses clerk-js 6.42.1.
- Set the OS clock ~3 minutes ahead, or in DevTools:
const real = Date.now.bind(Date); Date.now = () => real() + 200_000; - Keep the tab focused and watch the network panel:
POST …/tokensabout every 1.5 s (every 5 s when the tab is not focused).
Cause
In 6.42.1 the cache entry is created with createdAt: Math.floor(Date.now() / 1e3) and stores
expiresAt: Math.min(l.exp, n.createdAt + l.exp - l.iat)
and both the read path and the eviction timer compare it with the device clock (expiresAt - Math.floor(Date.now() / 1e3), evict at <= 5 / <= 0). With a fast clock localInsert + lifetime is later than exp, so min() picks the server exp, and exp - localNow is already negative (or below the 5 s buffer) at insert. The entry is dropped at once. Before 6.42 the check was (exp - iat) - (localNow - iat) <= 5, which has the same effect.
The poller (startPollingForSessionToken, 1500 ms while document.hasFocus(), else 5000 ms) calls session.getToken() on every tick, so every tick mints a token. Focus and visibilitychange refreshes add more.
#10401 states this directly ("Fast clocks behave as before") and notes that the clock offset cannot be measured in the browser because FAPI does not expose Date cross-origin. #10361, which would have aged tokens from the local insert time, was closed in favour of #10401.
Suggested fix
Any of these would make a fast clock harmless:
- For a token this client has just minted (response of
POST …/tokens), judge freshness by local elapsed time since insert against the token lifetime (exp - iat), as in #10361. Keep the currentmin()behaviour only for tokens that arrive already aged (hydratedlastActiveToken, another tab's broadcast), which is the case #10401 was protecting. - Or estimate the clock offset once from a freshly minted token (
localInsert - iat, accurate to about the request time) and use it in everyDate.now()comparison of the token cache and poller. - Or add
Dateto the Frontend API'sAccess-Control-Expose-Headers, so the SDK can measure the offset from any FAPI response.
As a workaround we are moving our GraphQL auth links to a token cache of our own that ages tokens with the monotonic clock since receipt, so our own requests stop depending on the device clock. The poller and focus refresh inside clerk-js still mint at the rates above, and only a fix in clerk-js can stop that.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.8k
- Forks
- 492
- Merge medio
- 1 d 7 h
- PR fusionados (30 d)
- 357
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de clerk/javascript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
clerk/javascript#10708 ·
Los mantenedores suelen responder en 1 día
-
Built-in reverification dialog lacks an accessible name (aria-dialog-name)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
clerk/javascript#10548 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
clerk/javascript#10547 ·
Los mantenedores suelen responder en 1 día
-
<SignIn />: first "Use email" click switches back to phone when `initialValues.phoneNumber` is setPosiblemente ocupada @twicestruck la tomó hace 20 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
clerk/javascript#10487 ·
Los mantenedores suelen responder en 1 día
-
useLoadedIsomorphicClerk misses "ready" when a ClerkProvider remounts after clerk-js has loaded — <ClerkLoading> never resolvesQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
clerk/javascript#10462 ·
Los mantenedores suelen responder en 1 día
Todos los issues de clerk/javascript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
vercel-labs/ui#809 ·
Los mantenedores suelen responder en 1 día
-
bot:ai-assisted component:platform-js status:untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
midnightntwrk/platform-js#38 ·
-
[bug] Second false positive on high-cost plugin alert: detection only compares patch entry id, community plugin dsh-auto | [bug] 高成本插件告警第二次误报:检测只比对 patch 条目 id,社区插件 dsh-auto-review 被认成 @deepseek-ai/dsh-experimental-auto-reviewPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ranxianglei/billion-context#7068 ·
Los mantenedores suelen responder en 1 día
-
vendor: bump whisper.cpp past 6a8addd — the current pin aborts the app on a failed Metal initAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mybigday/whisper.rn#348 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
six-group/six-webcomponents#600 ·