Repository navigation
Phase 2: Server/Conn API, graceful shutdown, logging, CI - #24
Merged
Merged
Conversation
Prepares for a second, Conn-based API next to EventHandler/UserData: the connection state machine now calls an internal connHandler, and the existing API is one implementation of it (legacyHandler). In-place sends also take their incremental-buffer reference in writeFrom, once per held segment, instead of once per OnTraffic call, so a callback may send several slices of the same buffer in place. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listen(network, address, handler, opts...) returns a Server; Serve blocks until Shutdown(ctx) or Close and returns ErrServerClosed. Options replace the positional NewMany arguments and URingNet fields (WithRings, WithBuffers, WithBusyPoll, WithZeroCopy, WithIdleTimeout, WithMaxWriteBuffer, WithLogger, ...). Handler callbacks get a *Conn: Write (in place when the data lies in the received buffer, copied otherwise), WriteNoCopy, Close (after queued data is sent), Context, addresses, and AsyncWrite/AsyncClose, which are safe from any goroutine. Actions are reduced to None, Close and Shutdown. OnClose receives the reason: nil, io.EOF, ErrIdleTimeout, ErrWriteTimeout, ErrServerClosed or the socket errno. Shutdown(ctx) stops accepting, lets each connection send what was already written, then closes it; connections still open when ctx ends are closed at once and ctx.Err() is returned. Also: - *slog.Logger for recovered failures (accept errors, zero-copy and buffer-registration fallbacks) and timeouts; silent by default. - Startup checks: ErrKernelTooOld below Linux 6.0, and ErrIOUringUnavailable with a hint when seccomp or kernel.io_uring_disabled blocks io_uring; ENOMEM hints at RLIMIT_MEMLOCK. - Port 0 with SO_REUSEPORT and several rings: all rings now bind the port the first one got (each used to get its own random port). - go 1.21 (log/slog). The EventHandler/UserData API keeps working unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the peer shut down its write side (EOF) the connection was closed at once, dropping replies still queued: a client that sends a request and then half-closes never got the answer (e.g. printf req | nc -N). On EOF, stop receiving, send what was written, then close; if the peer is fully gone the send fails and the connection closes anyway. OnClose still receives io.EOF. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both examples now use Listen/Serve with options and shut down gracefully on SIGINT/SIGTERM. Verified the HTTP example again with curl HTTP/1.0, ab, ab -k and pipelined requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New, NewMany, SetLoops, Ringloop, EventHandler, BuiltinEventEngine, UserData, NetAddress and the Echo/Read/Write/EchoAndClose actions are marked Deprecated in favour of Listen, Server, Handler and Conn. They keep working for now. Adds WithBusyPollThresholds, used by the bench server, which now runs on the new API. Throughput against master's old-API server is unchanged (0.91-1.06x over 6 scenarios, server on 1 core). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Test matrix on the go.mod minimum (1.21) and the latest release, with go vet, go test -race over all packages, example builds and a vet of the bench module; the runner's kernel is printed. - staticcheck as a separate job. - Coverage is now generated and uploaded (codecov-action v4); the separate codecov workflow, which uploaded nothing, is removed. - byteslice: replace the deprecated reflect.SliceHeader with unsafe.Slice, and skip the pool-reuse assertion under the race detector, which makes sync.Pool drop items at random. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Get Started sections now show Listen/Serve/Shutdown, the options, and Handler/Conn; incremental-buffer and zero-copy snippets use the new API. Both README examples compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
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.
Roadmap phase 2 (items 4, 5, 8, 9, 10, 11 and 19 in
docs/ROADMAP.md).New API
NewManyarguments andURingNetfields (WithRings,WithBuffers,WithBusyPoll,WithZeroCopy,WithMaxWriteBuffer,WithIdleTimeout,WithLogger, ...).Write(in place when the bytes lie in the received buffer, copied otherwise),WriteNoCopy,Close(after queued data is sent),Context, addresses, andAsyncWrite/AsyncClosefrom any goroutine.None,Close,Shutdown. OnClose gets the reason:nil,io.EOF,ErrIdleTimeout,ErrWriteTimeout,ErrServerClosedor the socket errno.Shutdown(ctx)stops accepting, lets connections send what was written, closes them; forced close andctx.Err()when ctx ends.*slog.Logger(accept failures, zero-copy/buffer fallbacks, timeouts); silent by default.ErrKernelTooOldbelow 6.0;ErrIOUringUnavailablewith a seccomp /kernel.io_uring_disabledhint; ENOMEM hints atRLIMIT_MEMLOCK.The
EventHandler/UserDataAPI keeps working and is marked Deprecated. Internally both APIs drive the same connection state machine through an internal handler interface.Fixes found along the way
printf req | nc -Ngot nothing). Now queued data is sent first.Other
go test -race ./..., vet, staticcheck, coverage upload (the old codecov workflow uploaded nothing). The runner kernel is 7.0; core coverage 77%.byteslice:reflect.SliceHeader→unsafe.Slice; pool-reuse assertion skipped under-race(the race detector drops sync.Pool items at random).go 1.21(log/slog).Testing
Lima VM (Linux 6.17) and CI (Linux 7.0): all tests pass under
-race; the 8 new API tests pass 10 runs in a row. HTTP example re-verified with curl/ab/ab -k/pipelining. Bench server on the new API vs master's old-API server: 0.91–1.06x across 6 scenarios (noise).🤖 Generated with Claude Code