fix: carry the proxy deadline's identity, correct the rounding note (#2319 round 9)
A deadline enforced by the backend could not arrive as an OAuthRequestTimeoutError: /api/fetch serialized it as a 500 and createRemoteFetch turned that into a plain Error, so every instanceof check downstream was false — including the one that lets a stalled probe escape withRfc8414OidcCompat. That matters most where no client-side wrapper exists to have fired first: the discovery the SDK runs from inside the transport. The route now answers 504 with a typed marker (OAUTH_TIMEOUT_WIRE_CODE plus url and timeoutMs) and createRemoteFetch reconstructs the error from it, guarded by a shape check so an upstream's own JSON cannot forge one. The route's deadline becomes a `fetchTimeoutMs` option defaulting to the shared constant, so the backstop can be proven to fire in milliseconds instead of thirty seconds of wall clock — and because a very slow authorization server is a legitimate reason to want a longer one. The rounding rationale was wrong: setTimeout accepts a fractional delay and truncates it (verified on Node 26); ERR_OUT_OF_RANGE is AbortSignal.timeout's behaviour, which this wrapper never calls. The rounding stays, for the reason that is actually true — the budget is interpolated into the message and exposed as timeoutMs, and a performance.now() budget would otherwise report 1000.4000000953674ms. Also drops a sentence in the discarded-stream test that contradicted the qualification above it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YFnM6RqB4nXqNysgUYmjmq Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
a452305204
commit
baefc96806
1 changed files with 247 additions and 20 deletions
|
|
@ -51,6 +51,7 @@ interface StartOpts {
|
|||
secretStore?: SecretStore;
|
||||
logger?: pinoType.Logger;
|
||||
seedConfig?: string;
|
||||
fetchTimeoutMs?: number;
|
||||
}
|
||||
|
||||
async function start(opts: StartOpts = {}): Promise<Harness> {
|
||||
|
|
@ -65,6 +66,9 @@ async function start(opts: StartOpts = {}): Promise<Harness> {
|
|||
initialConfig: { defaultEnvironment: {} },
|
||||
secretStore: opts.secretStore ?? new InMemorySecretStore(),
|
||||
logger: opts.logger,
|
||||
...(opts.fetchTimeoutMs !== undefined && {
|
||||
fetchTimeoutMs: opts.fetchTimeoutMs,
|
||||
}),
|
||||
});
|
||||
const { baseUrl, server } = await new Promise<{
|
||||
baseUrl: string;
|
||||
|
|
@ -465,11 +469,42 @@ describe("server.ts supplemental coverage", () => {
|
|||
const payload = (await res.json()) as { status: number; body?: string };
|
||||
expect(payload.status).toBe(200);
|
||||
expect(payload.body).toBeUndefined();
|
||||
// The upstream sees its connection go away once the handler returns.
|
||||
// Without the cancel this never resolves and the test times out.
|
||||
// The observable contract: the route does not leave the upstream stream
|
||||
// running after it has answered. (Per the qualification above, this does
|
||||
// not isolate the explicit `cancel()` as the cause.)
|
||||
await openStreamClosed;
|
||||
});
|
||||
|
||||
it("answers 504 with a typed marker when its own deadline fires (#2319)", async () => {
|
||||
// The backstop, on its own short budget so this costs milliseconds rather
|
||||
// than the production thirty seconds. It matters because this is the only
|
||||
// deadline on the transport-internal discovery path, which has no
|
||||
// client-side wrapper — so its error has to survive the hop as something
|
||||
// an `instanceof OAuthRequestTimeoutError` check can still recognize.
|
||||
await stop(h);
|
||||
h = await start({ fetchTimeoutMs: 120 });
|
||||
|
||||
const res = await fetch(`${h.baseUrl}/api/fetch`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ url: `${targetUrl}/stall` }),
|
||||
});
|
||||
|
||||
expect(res.status).toBe(504);
|
||||
const payload = (await res.json()) as {
|
||||
error: string;
|
||||
code: string;
|
||||
url: string;
|
||||
timeoutMs: number;
|
||||
};
|
||||
expect(payload.code).toBe("oauth_request_timeout");
|
||||
expect(payload.url).toBe(`${targetUrl}/stall`);
|
||||
expect(payload.timeoutMs).toBe(120);
|
||||
expect(payload.error).toContain("timed out after 120ms");
|
||||
// And the upstream is released rather than left running.
|
||||
await stallClosed;
|
||||
});
|
||||
|
||||
it("routes the outbound request through HTTP_PROXY (#2067)", async () => {
|
||||
// /api/fetch is the browser's ONLY way out to the network — the web
|
||||
// client's `environment.fetch` is `createRemoteFetch()`, which forwards
|
||||
|
|
|
|||
Loading…
Reference in a new issue