Repository navigation
Bound every backend client with a request deadline - #198
neuromechanist merged 8 commits into
Conversation
Deploying nemar-website with
|
| Latest commit: |
23c29e6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://58b0ba99.nemar-website.pages.dev |
| Branch Preview URL: | https://173-admin-api-clients-pass-a.nemar-website.pages.dev |
|
Both review findings addressed. 1.
|
| before | after | |
|---|---|---|
list |
5s | 5s |
deny |
15s (as decide) |
15s |
approve |
15s (as decide) |
120s |
120s is still a bound, which is the point — #173 was about an unbounded wait, not a short one. The real fix is making approve non-blocking (kick off the job, poll progress); that needs a backend change and is now tracked in #200, referenced from the constant's comment so it doesn't become a dangling note.
2. The tests now prove the wiring, not just the values
Reproduced the reported gap first: swapped approve's fallback to ADMIN_TIMEOUTS_MS.list and the whole suite stayed green, confirming the explicit timeoutMs: 10 in every case masks which constant the call site references.
Added a deadline wiring suite to all four test files that spies on AbortSignal.timeout and runs with no timeoutMs override, so the fallback becomes observable:
const spy = vi.spyOn(AbortSignal, "timeout");
await approvePublicationRequest("nm-xyz", { fetch: okFetch(...) });
expect(spy).toHaveBeenCalledWith(ADMIN_TIMEOUTS_MS.approve);Re-ran the same mutation against the new suite: passes the approve deadline when approving fails as it should. Mutation reverted.
Covers every call site across admin-api, dashboard-api, collaborators-api, and upload-client.
3. Non-blocking observation filed
The upload.astro finding — a failed finalize re-runs createDraftDataset from scratch instead of retrying finalize against the existing draft.id — is filed as #201. Agreed it's pre-existing and out of scope here; the PR makes it reachable via a hang rather than only via a hard failure, which is worth the follow-up.
Full suite green, typecheck 0 errors, lint clean.
|
Review re-verified. Both findings closed out, no new ones. On the 120s On the wiring tests: mutation-tested all four files, not just the one I had checked:
Each mutation was caught by exactly the test that should catch it and by nothing else. All reverted. On spy hygiene: On regressions: CI green across build, lint, test, typecheck, and Cloudflare Pages. |
Closes #173.
Problem
src/lib/admin-api.ts,dashboard-api.tsandcollaborators-api.tspassedsignal: init.signalon every fetch, wheresignalis optional and no caller supplied one. The existingtry/catchcovers a request that fails (refused connection, DNS, TLS). It does not cover one that hangs: a connection that opens and never writes a response never settles, so there is nothing to catch. These run during SSR at the edge, so the page render hangs with them.upload-client.tshad the same gap on its two JSON calls, which took no signal at all.Changes
New
src/lib/request-deadline.tsholds the singleresolveSignal(init, fallbackMs)(anAbortSignal.timeoutcombined with the caller's signal viaAbortSignal.any) plus the two shared constants. Four clients had already hand-copied that function, each carrying a "mirrors the other one deliberately" comment; they all import it now, so identical behaviour under a hung upstream is enforced by construction rather than by comment.Deadlines are per-operation, exported as a table per client so the differences are a pinned contract:
listdecide(approve/deny)liststatusmutatelistinvitecreatefinalizeThe byte-transfer path (
runUploadQueue/putToPresignedUrl) deliberately gets no deadline. Its signal is the user's cancel button and a multi-gigabyte PUT legitimately runs for minutes; a timeout there would abort healthy uploads. That is now stated in the code rather than being an accident.createDraftDatasetandfinalizeDatasetgained an optionalinitargument (fetch override + timeout), matching every other client, which is also what makes them testable.Tests
bun run test: 929 passing, up from 906.New suites drive the real abort path with a fetch that only settles by rejecting on its signal, per the convention in
imports-admin-api.test.ts— no fake timers. Each client covers: every call site aborts when hung, a caller-supplied signal still wins alongside the deadline, and the deadline ordering holds (decorative < primary < mutation).AbortSignal.timeout()does not expose its duration, so these pin the values, not the wiring — the same caveat already documented onIMPORT_TIMEOUTS_MS.bun run typecheck0 errors,bun run lintclean.