Skip to content

usockets: stop pause() from arming writable interest it never had - #37099

Open
robobun wants to merge 9 commits into
mainfrom
farm/7c2d84da/pause-shutdown-kqueue
Open

usockets: stop pause() from arming writable interest it never had#37099
robobun wants to merge 9 commits into
mainfrom
farm/7c2d84da/pause-shutdown-kqueue

usockets: explicit writable kicks replace the pause-armed one; kqueue…

199dbf3
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Aug 7, 2026 in 42m 18s

Code review found 1 important issue

Found 2 candidates, confirmed 2. See review comments for details.

Details

Severity Count
🔴 Important 1
🟡 Nit 1
🟣 Pre-existing 0
Severity File:Line Issue
🔴 Important packages/bun-usockets/src/socket.c:723-731 pause() then shutdown() (reversed order) still closes prematurely on kqueue
🟡 Nit packages/bun-usockets/src/socket.c:870 us_socket_resume() unconditionally arms WRITABLE — same spurious-drain class as pause()

Annotations

Check failure on line 731 in packages/bun-usockets/src/socket.c

See this annotation in the file changed.

@claude claude / Claude Code Review

pause() then shutdown() (reversed order) still closes prematurely on kqueue

The sibling ordering `pause()` **then** `shutdown()` still closes prematurely on kqueue: `pause()` on a READABLE-only accepted socket arms the 0-event `EVFILT_WRITE|EV_ONESHOT` fallback (own_shutdown is still false), and the new `raw_shutdown` direct `kqueue_change(..., /*old*/0, /*new*/0, ...)` enters `teardown_watch` but its `if (old_events & LIBUS_SOCKET_WRITABLE)` guard reads the passed literal `0` and cannot see that phantom one-shot — so it survives, echoes SS_CANTSENDMORE as `EV_EOF` on t

Check warning on line 870 in packages/bun-usockets/src/socket.c

See this annotation in the file changed.

@claude claude / Claude Code Review

us_socket_resume() unconditionally arms WRITABLE — same spurious-drain class as pause()

`us_socket_resume()` (the non-shut-down branch, ~24 lines below) still hardcodes `LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE`, so an idle socket doing `pause(); resume();` post-PR goes 0 → R|W and fires one spurious `drain` — the same class this PR fixes for `pause()`, and the new test never calls `resume()` so the round-trip is uncovered. Per REVIEW.md's "fix the whole class in the same PR", resume() should be `READABLE | (us_poll_events(&s->p) & WRITABLE)` (any real backpressure during paus