Skip to content

fix(eventStream): propagate source errors and unblock the deflate relay - #554

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-6-7-error-propagation
Sep 30, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-6-7-error-propagation

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

Two HIGH findings from the streaming-reader review land here together, because they are two halves of the same failure story: what happens when something goes wrong mid-stream. Finding 6 is a deadlock; finding 7 is a silently swallowed error. Both had been partially addressed on this branch — the deep paths (raw-dataset fallback, the deflate relay) already checked for a failed source — but the two most ordinary paths did not.

Finding 6 first. On the deflate path a relay coroutine inflates compressed bytes into a side stream that the body loop consumes, and a throttle keeps the relay from ballooning memory: when more than 16 KiB of inflated output is sitting unconsumed, the relay parks on bodyStream.awaitConsumerActivity(). The problem: if the body loop dies — concretely, if the listener throws during an event callback — there is no consumer anymore, so that activity never comes. Meanwhile the body loop's catch handler does await relayPromise to collect any inflate error before rethrowing. Each side waits for the other, forever, and the promise returned from fromPart10Stream never settles. The fix is a bodyFailed deferred: the body catch resolves it before awaiting the relay, and the relay races it inside the throttle gate, sees the flag, and winds down.

Finding 7 is quieter and nastier. The feed loop that pulls chunks from your source catches a source error into feedError — and then calls setComplete() so blocked readers wake up. But the normal completion path never looked at feedError again: to the body loop, a source that died at a top-level element boundary is indistinguishable from a file that genuinely ended there. I probed this against the pre-fix reader on the CT1_UNC explicit-LE fixture: a source that throws after 1,044 bytes resolved cleanly, handing the caller a well-formed-looking dataset with a fraction of the file's tags and no signal that the transfer failed. A cut mid-element (1,000 bytes) did reject — but with the downstream symptom (truncated: element at 998 declares 8 bytes but stream ended) instead of the source's own error. Now the clean-EOF path awaits the feed and throws feedError before endDataSet, and the body catch prefers inflateError ?? feedError ?? bodyErr, so the root cause is what surfaces.

The tests pin all three behaviors. The deadlock test is the finding's own reproduction:

class ThrowingListener extends EventStreamListener {
    count = 0;
    _baseStartElement() {
        if (++this.count === 25) throw new Error("LISTENER BOOM");
    }
}

// pre-fix: still pending after 5 s — relay and body catch each waiting
// on the other.  post-fix: rejects promptly with LISTENER BOOM.
await fromPart10Stream(chunked(deflateFixture, 512), new ThrowingListener());

And the source-error tests use an async generator that yields the first N bytes and then throws NETWORK BOOM, at both probed cut points — the boundary cut that used to resolve cleanly and the mid-element cut that used to mask the cause. Both now reject with the source's error. All three tests were verified failing (the deadlock one by hang-then-timeout) before the fix went in; the full suite is green at 634 passing.

🤖 Generated with Claude Code

Review findings 6 and 7, both HIGH, both previously only partially
fixed on this branch.

Finding 6: the deflate relay throttle parked solely on
bodyStream.awaitConsumerActivity() while the body-loop catch awaited
relayPromise, so a listener that threw mid-parse left each side
waiting for the other and the returned promise never settled. The
body catch now resolves a bodyFailed deferred before awaiting the
relay, and the relay races that deferred inside its throttle gate and
winds down.

Finding 7: feedError was only re-checked in the raw-dataset fallback
and the deflate relay; the normal native completion path treated a
source error's setComplete() as a clean EOF. The clean path now awaits
the feed and throws feedError before endDataSet, and the body catch
prefers inflateError ?? feedError ?? bodyErr so the root cause is what
surfaces.

Tests: a throwing listener on the deflate fixture pins the deadlock
(promise must settle within a timeout), and an async-generator source
that throws after N bytes — cut at an element boundary (1044) and
mid-element (1000), both probed against the pre-fix reader — pins
that the source's own error is what the caller sees.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit e78a97e into release/1.0-beta-core Sep 30, 2026
8 checks passed
@awatson1978
awatson1978 deleted the core/finding-6-7-error-propagation branch September 30, 2026 13:26
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant