{"record":{"id":"f6d923bd007d26cc","repo":"toeverything/AFFiNE","slug":"auth-session-temporarily-unavailable","errorCode":"auth_session_temporarily_unavailable","errorMessage":"Auth session service is temporarily unavailable.","messagePattern":"Auth session service is temporarily unavailable\\.","errorType":"http","errorClass":"AuthSessionTemporarilyUnavailable","httpStatus":504,"severity":"error","filePath":"packages/backend/server/src/core/auth/access-token.ts","lineNumber":63,"sourceCode":"    const ttl = this.config.auth.token.accessTokenTtl;\n    for (let attempt = 0; attempt < SIGNING_KEY_RETRY_LIMIT; attempt++) {\n      const issuedAt = Math.floor(Date.now() / 1000);\n      const expiresAtSeconds = issuedAt + ttl;\n      const expiresAt = new Date(expiresAtSeconds * 1000);\n      const key = await this.keys.active();\n      const token = signAuthSessionAccessToken(\n        userId,\n        authSessionId,\n        key.id,\n        key.secret,\n        issuedAt,\n        expiresAtSeconds\n      );\n      if ((await this.keys.active()).id === key.id) {\n        return { token, expiresAt };\n      }\n    }\n    throw new AuthSessionTemporarilyUnavailable();\n  }\n\n  async verify(token: string): Promise<AuthSessionPrincipal> {\n    const keyId = authSessionAccessTokenKeyId(token);\n    if (!keyId) {\n      throw new SessionAccessTokenError('ACCESS_TOKEN_INVALID');\n    }\n    const key = await this.keys.verify(keyId);\n    if (!key) throw new SessionAccessTokenError('ACCESS_TOKEN_INVALID');\n    const verified = verifyAuthSessionAccessToken(\n      token,\n      keyId,\n      key.secret,\n      Math.floor(Date.now() / 1000)\n    );\n    if (verified.status !== 'valid') {\n      throw new SessionAccessTokenError(\n        verified.status === 'expired'","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/server/src/core/auth/access-token.ts#L45-L81","documentation":"sign retries reading the active signing key up to SIGNING_KEY_RETRY_LIMIT times; AuthSessionTemporarilyUnavailable is thrown when the key keeps rotating between read and check, meaning token signing must be attempted again shortly.","triggerScenarios":"Thrown at packages/backend/server/src/core/auth/access-token.ts:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["This is a transient 503 — retry the request after a short backoff; the auth session store (e.g. Redis/DB) is briefly unreachable.","Check server logs for connectivity problems to the session storage backend.","If it persists, verify the database/redis connection config for the auth module."],"exampleFix":"async function withRetry(fn: () => Promise<Response>) {\n  for (let i = 0; i < 3; i++) {\n    const res = await fn();\n    if (res.status !== 503) return res;\n    await new Promise(r => setTimeout(r, 2 ** i * 200));\n  }\n  throw new Error('Auth service unavailable');\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}