Files
CatoandClaude 19ffeaff74 fix(auth): a session read that hangs cannot take the site down (#298)
On 2026-10-30 every Substrata page answered 502 after 23 seconds for hours
while /api/health still answered 200: session reads hung (get-session took
251 s) and every page waits for one. A restart cleared it; the cause was not
visible from outside the box.

- currentSession() gives up after 4 s and answers "signed out", logged, so a
  public page always renders.
- Accounts read from their own small pool, so a session read never queues
  behind long research queries for one of the five shared connections, and
  the server cancels any account query after 5 s instead of letting it hold
  its connection forever.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 10:00:49 +01:00

24 lines
744 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { within } from '../lib/within';
test('an answer in time passes through', async () => {
assert.equal(await within(Promise.resolve('reader'), 50, 'session read'), 'reader');
});
test('no answer in time is a rejection that names what hung, not a hang', async () => {
const started = Date.now();
await assert.rejects(
within(new Promise(() => {}), 30, 'session read'),
/session read: no answer within 30ms/,
);
assert.ok(Date.now() - started < 1000);
});
test('a failure inside passes through as itself', async () => {
await assert.rejects(
within(Promise.reject(new Error('relation missing')), 50, 'x'),
/relation missing/,
);
});