Skip to content

Fix the bugs found in S3 (#263 #266 #267 #268 #270) - #275

Merged
xuckless merged 11 commits into
mainfrom
fix/s3bugs
Nov 27, 2026
Merged

xuckless merged 11 commits into
mainfrom
fix/s3bugs

Conversation

@xuckless

@xuckless xuckless commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

The bugs I found during S3, one commit each, plus three small leftovers. Specs: research/post070/s3bugs.md.

Tests: scoped filters per item (sse, WebSocket, ResponseCache, peel, grpc, MessageQueue, nats, s3, body, plus capi-test for s3), then test, capi-test and test-compile-errors (2352 passed, 178 skipped), test -Dhttp3=false -Dtest-filter=grpc test-stress -Dtest-filter=sse, and ReleaseSafe for the sse, WebSocket and grpc filters. No benchmarks.

Not done: the perf stat gate for #270 (one enum compare before the existing branch; no benchmarks during S3), and an .h2 row for #268 (the h2 client has no GOAWAY test hook; the .h3 row exercises the same redial).

Closes #263
Closes #266
Closes #267
Closes #268
Closes #270
Closes #251
Closes #256
Closes #257

serveFallback's handler task is the subscriber's sender. A publish after
its loop ended claimed a sender (open(idle) -> open(running)) that only
set wake, so finishSubscriber's awaitSender waited forever: the handler
hung and the subscriber leaked. finishSubscriber now applies sender_idle
for a fallback subscriber after .finish (left(e, s) x sender_idle, an
existing cell). Both catches in the loop record the cancel and the task
re-raises it with io.recancel() after finishSubscriber.

Test: topics_test, a fallback subscriber claimed by a publish after its
loop ends (Topics._finish, a test hook).
Between register and a park that fails with Unsupported, a publish past
max_queued_bytes moved the subscriber to opening(graceful) and queued the
end; abandon dropped the queue and the end with it, and the second
register queued only the open line and the replay, so the fallback
stream never ended. register's non-draining branch now queues the end
again when the life already holds one (pushEnd, shared with beginClose):
close_reason stays .slow and closed_slow counts once. The draining branch
is unchanged (queueDrainEnd queues its own end).

Test: topics_test, both branches through the _register/_fallBack hooks.
Batch.hold chose the backstop or the thread path by the caller's thread,
so a hold from a thread with no executor on a joined batch spawned a
flusher under the write lock while endIfIdle and Backstop.run write the
task under home.mutex: two flushers, or a task left none or running with
nobody to flush. hold now takes the backstop path whenever the batch is
joined or queued (member != .free), from any thread; the thread path is
left to free batches only. Docs updated.

Test: a hold off the executors on a joined and on a queued batch queues
it and starts no flusher.
register and checkRoute tested isCached on the outermost handler type, so
doc(texts, cached(o, h)) got no ResponseCache and compiled on a POST
route, while routeInfo and openapi reported it cached. Both now read the
peeled markers: handlers.cacheOptions (the outermost cached's options)
and anyCached.

Tests: ResponseCache rows for cached, doc(cached), cached(doc),
doc(cached(noWait)), noWait and doc alone; the peel table checks
cacheOptions; compile error 14 (doc(cached) on app.post).
…them (#268)

redial and autoH3 kept every replaced connection until Channel.close, so
a long-lived channel that redials grew without bound. An owned channel
now counts its calls: openOn leases before pick reads a slot, the
stream's deinit (or a failed open) gives it back, and the last lease out
closes both retired lists with the lock let go. A retired connection is
in no slot, so a call that leases after the retire cannot reach it, and
one that read it before already holds a lease. The slot loads and
stores are atomic (seq_cst, with the lease count), which also closes the
plain-load race on conn/h3 (D2). transport() leases around its look;
runtime() reads the channel's io instead of a connection's. Owned grows
by its io and the u32 count; two uncontended RMWs per call.

Test: h3_test, three redials leave nothing retired; a bidi stream on a
replaced connection keeps it until it ends; a canceled call gives its
lease back.
The End -> result switch, with its unreachable closed arm, is one
comptime EnumArray(End, ?NextError) (end_error; null: next returns
null). Closed still fails at once, before the messages; every other end
after the drain. No behaviour change; the existing next tests cover all
six cells.
Upload's sections allocate (copyIn's appends, the finish path, setFailure's
dupes) under what was a spin lock. It is a std.Io.Mutex now, taken with
lockUncancelable(self.io) in the same lock()/unlock() pair, so no call
site changes. The C ABI's upload write takes it from the host thread:
zio parks a foreign thread on its own futex.
request.zig and client.zig each declared the same unread / reader_taken
/ cached union with its own table. It is one pub BodyState in
request.zig, with one table documenting both reactions of reader_taken
(the request: error.BodyReaderTaken; the client: its debug assert);
client.zig aliases it. No behaviour change.
@xuckless
xuckless merged commit 93310a0 into main Nov 27, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment