Skip to content

Give up on a fetch that ignores its abort signal - #35

Merged
dmccoystephenson merged 2 commits into
mainfrom
feat/give-up-on-fetch-that-ignores-abort
Nov 6, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
feat/give-up-on-fetch-that-ignores-abort

Conversation

@dmccoystephenson

@dmccoystephenson dmccoystephenson commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • send() now has its own bound. The fetch is raced against the timeout, so an attempt is given up at timeoutMs even when a custom fetch ignores its abort signal: the slot is freed, the drop is logged, and the report() promise resolves, as its TSDoc already said it would.
  • The abort still runs first, so a fetch that honours it and rejects at once still reports its own failure. A fetch that ignores it gets the debug line could not deliver <body>: Error: no answer within <n>ms.
  • A late answer or failure from such a fetch is discarded, its body unread, as A fetch that ignores its abort signal holds its in-flight slot forever #33 anticipated.
  • The body read is raced too. A body that never ends no longer holds the slot, and is not logged as a drop, because the server has answered by then. This keeps the existing rule that an unreadable body is never a failed delivery.
  • The README fetch row, the fetch option TSDoc and CHANGELOG.md [Unreleased] say the same.

Closes #33

Changed test

flush() and close() with no argument wait at most the client's own timeout, even when fetch ignores the abort now gives each drain its own client. With the fix, the attempt ends at the timeout, so the close() that followed flush() on one shared client had nothing left to wait on. Its assertions are kept. Its < 2000 bound no longer tells a default of timeoutMs apart from TIMEOUT_MS, because the attempt itself now ends at the client timeout, so that difference is no longer observable through a default drain.

Test plan

  • CI test job is red on the tests-only commit d52ee66, naming exactly the three new tests (run 42160971470: # tests 76, # pass 73, # cancelled 3, each hitting its test timeout)
  • CI test job, including npm run typecheck, is green on the head commit cbd20f7 (run 42161116862: # tests 76, # pass 76, # fail 0, # cancelled 0)
  • Local anchor recorded as UNVERIFIED: node is absent from this environment, so CI on the head SHA is the gate

Cross-client parity

No cross-client-visible behavior changed: the wire format, opt-out values and disabledReason strings are untouched, and the request in send() is only re-indented. The fetch option is specific to this client. trace-client-python and trace-client-java were not inspected for an equivalent problem.

CHANGELOG

CHANGELOG.md gained an entry under [Unreleased]. The version string is unchanged.

CI covers Node 22 only, so nothing here ran in the Next.js Edge runtime, Cloudflare Workers or Node 18. The change adds only Promise.race and Error, both within the ES2022 baseline. Whether a real fetch rejects with its AbortError or loses the race to the no answer within error was not pinned by a test; either way a could not deliver line is logged.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 2 commits November 5, 2026 21:10
Regression tests for #33, which fail until send() has its own bound: a
fetch that ignores its abort signal, a late answer or failure, and a body
that never ends. The flush()/close() drain test gives each drain its own
client, since the second drain would otherwise find nothing in flight
once attempts are given up at the timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
send() relied on the fetch honouring the abort, so a custom fetch that
dropped the signal left report()'s promise unsettled and held its
in-flight slot for good. Race the fetch and the body read against the
timeout instead. Closes #33.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head cbd20f7, not an independent review):

  • Scope: PASS — four files changed; each serves A fetch that ignores its abort signal holds its in-flight slot forever #33 (trace-client.ts fix, tests, README fetch row, CHANGELOG).
  • Tests-new: PASS — no new public member was added; three new tests cover the new behavior.
  • Tests-fix: PASS — established on CI because node is absent locally: run 42160971470 on tests-only d52ee66 left exactly the three new tests failing (73 passed, 3 cancelled by their timeouts); run 42161116862 on cbd20f7 passed 76 of 76.
  • Sibling structure: PASS — no new file; tests sit in the TraceClient block beside the other slot tests.
  • Sibling renames: PASS — nothing renamed.
  • Docs: PASS — the report() TSDoc claim "settles when ... the attempt has been given up" is now true without an edit; the README "Bounded" row, debug paragraph and wire-format section still hold; fetch row, fetch TSDoc and CHANGELOG were updated.
  • Issue resolution: PASS — the "Expected" of A fetch that ignores its abort signal holds its in-flight slot forever #33 is covered: slot freed, drop logged, promise resolved, whatever the fetch does.
  • CI: PASS — the test job is green on the head SHA.
  • Zero-dependency: PASS — no ^import line in trace-client.ts; package.json untouched; no test import added.
  • Edge gate intact: PASS — tsconfig.json untouched; npm run typecheck green in CI.
  • Never-throws / never-rejects: PASS — givenUp is subscribed by Promise.race before its timer can fire, so a rejection is never unhandled; a synchronous throw from doFetch skips the race but the finally clears the timer first; the body race ends in .catch; the new wait is bounded by timeoutMs.
  • No console: PASS — the only console. in the file is the existing doc example at trace-client.ts:156.
  • Export surface: PASS — exported values remain the four; the 0.1.0 compatibility test is untouched.
  • Version agreement: PASS — no version string changed.
  • Changelog: PASS — bullet added under [Unreleased].
  • Cross-client parity noted: PASS — stated in the PR body; the counterpart clients were not inspected.

Do-not-auto-merge check: no listed path matched. send() is on the list only for wire-format changes; endpoint, headers and JSON fields are re-indented, not changed.

Judgment calls and findings:

  • tests/trace-client.test.ts:843 — the drain test was restructured rather than left alone, because the fix makes the second drain on a shared client return at once. Its assertions are kept, and the PR body records that a default of TIMEOUT_MS can no longer be told apart from timeoutMs through a default drain. That difference is no longer observable behavior, so no coverage of a reachable state was lost.
  • trace-client.ts:449 — a late response's body is left unread, so its connection is not reused and is held until the runtime collects it. This was accepted in A fetch that ignores its abort signal holds its in-flight slot forever #33 and applies only to a fetch that already ignores its signal.
  • tests/trace-client.test.ts:356 — the sleep(50) in the late-result test backs a negative assertion. It cannot flake red; on a slow runner it could only pass without having observed the late result.
  • Local anchor: UNVERIFIED, node is absent here. CI on the head SHA is the gate. Nothing ran in the Edge runtime, Workers or Node 18.

No Phase 4 item failed, so no follow-up commit is needed.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 954f35f into main Nov 6, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feat/give-up-on-fetch-that-ignores-abort branch November 6, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A fetch that ignores its abort signal holds its in-flight slot forever

1 participant