History

Auto-merged main into fix/gmail-settings-scopes on deployment.

Rhys Sullivan committed 2 months ago

Commit e77e09c2 parents 46cea2c c0d25e42 files · +23 −1Browse files

Unified · Split

2 files
  1. apps/cloud/src/auth/jwks-cache.ts +14 −1
  2. apps/cloud/src/auth/workos.ts +9 −0
apps/cloud/src/auth/jwks-cache.ts+14−1
@@ -113,6 +113,10 @@ export interface CachedRemoteJWKSet extends JWTVerifyGetKey { · 112 unmodified lines
113113 blockingFetchCount: number;
114114 storeHitCount: number;
115115 lastFetchDurationMs: number | null;
116+ /** Wall-clock of the last cross-isolate store read (I/O). */
117+ lastStoreReadMs: number | null;
118+ /** Wall-clock of the last key resolution — WebCrypto `importKey`. */
119+ lastResolveMs: number | null;
116120 };
117121 }
118122
@@ -272,6 +276,8 @@ export const createCachedRemoteJWKSet = ( · 153 unmodified lines
272276 let blockingFetchCount = 0;
273277 let storeHitCount = 0;
274278 let lastFetchDurationMs: number | null = null;
279+ let lastStoreReadMs: number | null = null;
280+ let lastResolveMs: number | null = null;
275281
276282 const isFresh = (candidate: CacheEntry): boolean => Date.now() - candidate.fetchedAt < ttlMs;
277283 const isUsable = (candidate: CacheEntry): boolean =>
@@ -314,7 +320,9 @@ export const createCachedRemoteJWKSet = ( · 36 unmodified lines
314320 if (!store) return null;
315321 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: the L2 store is an optimization; any failure degrades to an upstream fetch
316322 try {
323+ const storeReadStartedAt = Date.now();
317324 const stored = await store.get(url);
325+ lastStoreReadMs = Date.now() - storeReadStartedAt;
318326 if (!stored) return null;
319327 const candidate = entryFrom(stored);
320328 if (!isUsable(candidate)) return null;
@@ -364,7 +372,10 @@ export const createCachedRemoteJWKSet = ( · 43 unmodified lines
364372 const current = await ensureFresh(false);
365373 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: jose JWTVerifyGetKey retry path is defined by thrown resolver failures
366374 try {
367− return await current.resolver(protectedHeader, token);
375+ const resolveStartedAt = Date.now();
376+ const key = await current.resolver(protectedHeader, token);
377+ lastResolveMs = Date.now() - resolveStartedAt;
378+ return key;
368379 } catch (error) {
369380 // Likely cause: keys rotated upstream after our TTL window started, or
370381 // we answered from a stale entry. Refetch once and try again. Anything
@@ -394,6 +405,8 @@ export const createCachedRemoteJWKSet = ( · 23 unmodified lines
394405 blockingFetchCount,
395406 storeHitCount,
396407 lastFetchDurationMs,
408+ lastStoreReadMs,
409+ lastResolveMs,
397410 }),
398411 });
399412 return result;
apps/cloud/src/auth/workos.ts+9−0
@@ -277,6 +277,15 @@ const verifySealedSessionLocally = ( · 276 unmodified lines
277277 ...(jwksAfter.lastFetchDurationMs === null
278278 ? {}
279279 : { "jwks.last_fetch_ms": jwksAfter.lastFetchDurationMs }),
280+ // Splits the ~3.4s that sits inside jwt_verify with zero upstream
281+ // fetches: the cross-isolate store read (I/O) vs WebCrypto key
282+ // import vs the signature check itself.
283+ ...(jwksAfter.lastStoreReadMs === null
284+ ? {}
285+ : { "jwks.store_read_ms": jwksAfter.lastStoreReadMs }),
286+ ...(jwksAfter.lastResolveMs === null
287+ ? {}
288+ : { "jwks.key_resolve_ms": jwksAfter.lastResolveMs }),
280289 });
281290 }),
282291 );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t