fix(planner/brouter): add 30s timeout to outbound fetch
Mirrors journal PR #5. `fetchSegment()` and `computeSegmentGpx()` in lib/brouter.ts called `fetch()` with no AbortSignal — a hung or slow BRouter would stall the request handler indefinitely. New `lib/http.server.ts::fetchWithTimeout()` (same as the journal's helper) wraps fetch with `AbortSignal.timeout(30_000)`, composable with a caller-supplied signal via `AbortSignal.any()`. Tests: lib/http.server.test.ts (2 cases — timeout abort, happy path).
This commit is contained in:
parent
e647a29633
commit
d70d6ee8a8
3 changed files with 46 additions and 2 deletions
15
apps/planner/app/lib/http.server.ts
Normal file
15
apps/planner/app/lib/http.server.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Default timeout for outbound HTTP calls to third-party services
|
||||
// (BRouter, Overpass, …). A hung upstream must not stall the request
|
||||
// handler indefinitely.
|
||||
export const DEFAULT_EXTERNAL_FETCH_TIMEOUT_MS = 30_000;
|
||||
|
||||
export function fetchWithTimeout(
|
||||
input: RequestInfo | URL,
|
||||
init: RequestInit = {},
|
||||
timeoutMs: number = DEFAULT_EXTERNAL_FETCH_TIMEOUT_MS,
|
||||
): Promise<Response> {
|
||||
const signal = init.signal
|
||||
? AbortSignal.any([init.signal, AbortSignal.timeout(timeoutMs)])
|
||||
: AbortSignal.timeout(timeoutMs);
|
||||
return fetch(input, { ...init, signal });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue