Skip to content

fix(tcp): honor passive receive timeouts - #89

Merged
mremond merged 1 commit into
mainfrom
infinitary-batch/fb369be0
Nov 24, 2026
Merged

mremond merged 1 commit into
mainfrom
infinitary-batch/fb369be0

Conversation

@mremond

@mremond mremond commented Nov 24, 2026

Copy link
Copy Markdown
Member

Why

A program waiting for socket data can hang even when it asks to stop waiting after a set time.

What changed

  • Programs receive a timeout result when their requested wait expires.
  • A zero wait checks for data without pausing.
  • Bytes already received remain available after a timeout, including when delivery switches modes.

Before and after

Before: A receive with a 60 ms wait kept waiting until the three-second test limit stopped it.

After: Idle reads of lengths 0 and 4 returned a timeout at 60 ms; zero-wait checks finished at 0 ms. Approving queues this version for the next batch; that batch must pass the project checks before merging.

This changes socket results rather than a screen; kept native transcripts show the returned values and elapsed time.

Checked

Live validation: Demonstrated for this version. 1 of 1 scenarios driven live in the product.

Scenario Result Evidence
Finite receives on idle connected sockets ✅ Passed live Native sockets returned {error, timeout} at 60 ms for lengths 0 and 4; both zero polls returned at 0 ms.
  • Regression rejection: The unchanged runtime exceeded the three-second watchdog; the active-recovery regression rejected the initial repair with 12,288 bytes undelivered.
  • Repeated socket checks: Both native fixtures passed ten times in each scheduler configuration; three focused unit cases passed thirty executions, without retries.
  • Rust gate: Strict lint passed; the complete workspace passed 2,257 tests with one existing ignored test.
  • Complete native gate: All 546 runnable fixtures passed; two external OneCached fixtures were unavailable. Allocator, stacktrace, timer and cross-object checks passed.
  • Independent review and settled repairs: Review found stranded bytes and repeated copying; buffered readiness and a shared queue repair both within the existing recovery contract.
  • Review plan repair: Recorded the missing required idle scenario under the existing review rule; the proof boundary and product behavior did not change.
How it was checked

Built the runtime before the compiler: cargo build --release --locked -j 2 -p nera-runtime; cargo build --release --locked -j 2.

Ran cargo clippy --workspace --all-targets --locked -j 2 -- -D warnings and cargo test --workspace --locked --no-fail-fast -j 2 under umask 0022.

Ran the complete native suite: ./target/release/nera test -j 1 --timeout 30.

Ran both tcp_recv_timeout fixtures ten times with default schedulers and ten times with NERA_SCHEDULERS=1; ran the new cleanup unit and two mechanically updated reactor cases ten times each.

The new cleanup unit rejected reversed deadline comparison. The timeout fixture rejected the unchanged runtime, and the active fixture rejected incomplete retained-byte delivery.

Ran scripts/test-allocator-config.py, scripts/test-stacktrace-order.py and scripts/test-native-timer.py; all eight timer groups passed.

Ran scripts/test-cross.sh for x86_64-apple-darwin and aarch64-unknown-linux-gnu; inspected the resulting Mach-O and ELF object formats.

Compared both socket fixtures with the available Erlang reference runtime. A separate backend probe established why the transition assertion checks byte order rather than one packet boundary.

Risk

Risk above low: Blast radius, medium — TCP readers, reactor waits and active delivery share the retained-byte queue.; Novelty, medium — Deadline tracking and retained-byte recovery extend the existing reactor.

Full risk assessment
Dimension Level Why
Blast radius medium TCP readers, reactor waits and active delivery share the retained-byte queue.
Behavior low Finite receives now honor the timeout callers already supplied.
Undo low A code revert is sufficient; no stored data is migrated.
Evidence low Real native sockets demonstrate replies, elapsed time and recovery with both scheduler settings.
Sensitivity low No sign-ins, credentials, payments or persistent user data are changed.
Novelty medium Deadline tracking and retained-byte recovery extend the existing reactor.
Dependencies low No dependency is added or updated.
Not done

Native execution was demonstrated on Linux only; cross-object checks do not establish execution on other operating systems.

Two OneCached fixtures require external modules and remain skipped.

Programs receive a timeout result when their requested wait expires.

A zero wait checks for data without pausing.

Bytes already received remain available after a timeout, including when delivery switches modes.
@github-actions github-actions Bot added this to the 0.1.1 milestone Nov 24, 2026
@mremond
mremond merged commit c8bbd15 into main Nov 24, 2026
22 checks passed
@mremond
mremond deleted the infinitary-batch/fb369be0 branch November 24, 2026 15:20
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.

1 participant