host streams: a trap out of pump()'s sync half is recorded and the op withdrawn (review) - #305
Merged
Merged
Conversation
… withdrawn `HostActivity.pump()`'s synchronous `serviceSettled()/tick()` loop had no try/catch, and every host stream/future op invokes it inside its `new Promise(executor)` after setting `parked.*`. A trap from `tick()` therefore went one of two bad ways: - the trapping instance held an end of THIS stream: the poisoning retirement walk had already settled the op's promise, so the executor's throw was discarded — the component fault was mute (unlike `#pumpAsync`, which records `store.hostFailure`); - otherwise: the promise rejected, but `parked.*` stayed true and the host buffer stayed in the shared pending slot forever — every later op on that end threw "a write is already in flight", and a direct session's dead `pending` state re-ran the embedder's callback on the next guest op. The sync half now records `store.hostFailure ??= e` and rethrows (the one channel `#pumpAsync` already uses), and each op's executor withdraws on a throw — resets its `parked` flag and, while the pending slot is still its own buffer/session, `shared.cancel()`s it, the same withdrawal `cancelWrite`/`cancelRead`/`cancelDirect` perform (`retractDirect` is `cancelDirect`'s pending-slot half, factored out and shared). Regression: host_pump_trap_test.ts (write, read, and the silent-fault variant). Neighbouring suites (host_pump, host_arm, direct_streams, streams_teardown, e2e_streams, embedder/) unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adversarial correctness review of
main@ 396a216, streams track — the one MEDIUM finding.HostActivity.pump()'s synchronousserviceSettled()/tick()loop had no try/catch and runs inside every host stream/future op'snew Promise(executor)afterparked.* = true. A trap fromtick()was either mute (the trapping instance held an end of this stream, so the retirement walk had already settled the op's promise and the executor's throw was discarded — unlike#pumpAsync, which recordsstore.hostFailure) or wedging (otherwise the promise rejected butparked.*stayed true and the host buffer stayed in the shared pending slot forever: every later op threw "a write is already in flight"; a direct session's deadpendingstate re-ran the embedder's callback).Fix: the sync half records
store.hostFailure ??= eand rethrows (the channel#pumpAsyncalready uses), and each op's executor withdraws on a throw — the same withdrawalcancelWrite/cancelRead/cancelDirectperform (retractDirectiscancelDirect's pending-slot half, factored out and shared).Regression:
host_pump_trap_test.ts(write, read, silent-fault variants). Neighbouring suites (host_pump, host_arm, direct_streams, streams_teardown, e2e_streams, embedder/) unchanged.Gates:
just test-runtimegreen;just conformance0 failed; fulljust gatesgreen on the union of the five review PRs.Related open question from the same track (sync-half re-entrancy, not addressed here): #298.
Automerge armed.