Repository navigation
epoll fallback, TLS, English comments and architecture doc (roadmap 5, 14, 22) - #30
Merged
Merged
Conversation
Event loops now run on an internal eventLoop interface with two implementations: io_uring (iouring-go Loop) and a new epoll backend. The epoll loop emulates the operations the package uses: multishot accept/recv/recvmsg keep reading while the fd is readable, receives take buffers from an emulated buffer pool (a LIFO free list; -ENOBUFS when empty, so the existing pause/resume logic applies), sends retry on EPOLLOUT, connect completes on EPOLLOUT, timers use a heap, and every completion is queued and delivered after the submitting call returns, as with io_uring. The connection state machine, dialing, UDP and timeouts are unchanged; the Prep-based SQE code moved into the io_uring backend. WithBackend / URingNet.Backend: BackendAuto (default) falls back to epoll with a warning when io_uring is unavailable (blocked by seccomp, kernel.io_uring_disabled, or a kernel before 6.0); BackendIOUring and BackendEpoll force one. Server.Backend and PacketServer.Backend report the backend in use. epoll has no zero-copy send, recv bundles or incremental buffers. Verified with kernel.io_uring_disabled=2 in the VM: Listen falls back, logs the warning and serves. The whole test suite passes on both backends (URINGNET_BACKEND=epoll; CI runs both). Throughput of the epoll backend is 0.77-1.18x of the hand-written epoll server in bench/ (server on 1 core); the bench server gets -backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All comments in the Go sources (library, tests, examples, bench) are now in English; an AST comparison confirmed that only comments changed. docs/ARCHITECTURE.md describes the layers, the threading model, the receive and send paths with the buffer lifecycle, closing, backpressure and timeouts, dialing, UDP, framing, the epoll backend, memory use and the testing strategy; both READMEs link to it. Roadmap item 22 done; item 16 (zero-copy receive) dropped, as it needs datacenter NICs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TLS connections run crypto/tls over an in-memory transport fed by the event loop. The handshake runs on a goroutine of its own (crypto/tls cannot pause a handshake halfway); OnOpen runs once it succeeded, and Dial returns only then. Afterwards the goroutine exits and the transport turns non-blocking: an incomplete record yields a temporary net.Error, which crypto/tls does not treat as fatal after the handshake, so records are decrypted and passed to OnTraffic on the loop thread with no goroutine switch. The receive buffer is only lent to crypto/tls, and Write encrypts straight into the send queue, reusing send buffers. Close sends close_notify; the peer's close_notify or EOF closes after the data before it was delivered. Backpressure, timeouts, Framed and both backends work as for plain connections. Failed handshakes close the connection without OnOpen/OnClose and are counted (Stats.TLSHandshakeErrors). Conn.TLSConnectionState reports the negotiated state. WithDialTLS uses the dialed host as the server name unless the config sets one. Measured against a crypto/tls server (server on 1 core): 0.93-1.24x for 128-byte messages, 0.8x for 16KB. A first version with a decrypting goroutine per connection reached only 0.33-0.42x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #30 +/- ##
==========================================
+ Coverage 66.62% 70.13% +3.50%
==========================================
Files 22 25 +3
Lines 1579 2146 +567
==========================================
+ Hits 1052 1505 +453
- Misses 527 641 +114 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
epoll fallback (item 5)
eventLoopinterface: io_uring (iouring-go) and a new epoll backend that emulates multishot accept/recv/recvmsg, the provided-buffer pool (LIFO;-ENOBUFSwhen empty), send retry onEPOLLOUT, connect, timers and deferred completions — so the connection state machine, dialing, UDP and timeouts are unchanged.WithBackend:BackendAuto(default) falls back to epoll with a warning when io_uring is unavailable (seccomp,kernel.io_uring_disabled, kernel < 6.0). Verified for real withkernel.io_uring_disabled=2(this caught a bug in the first fallback check).Server.Backend().URINGNET_BACKEND=epoll; CI runs both). epoll throughput: 0.77–1.18x of the hand-written epoll server in bench/.TLS (item 14)
WithTLS/WithDialTLS,Conn.TLSConnectionState,Stats.TLSHandshakeErrors.OnOpenafter the handshake;Closesendsclose_notify.net.Errorfor incomplete records, which crypto/tls tolerates after the handshake — checked in Go 1.22 and 1.27 sources).English comments and architecture (item 22)
docs/ARCHITECTURE.md: layers, threading, receive/send paths and buffer lifecycle, closing, backpressure/timeouts, dial, UDP, framing, TLS, epoll backend, memory, testing.Item 16 (zero-copy receive) is dropped: it needs datacenter NICs.
Tests
New: backend tests (explicit epoll, selection logic, epoll buffer starvation) and 4 TLS tests (std client ↔ uringnet server with 1MB + half-close/close_notify, handshake failure, uringnet client ↔ std and uringnet TLS servers incl. untrusted cert, Framed over TLS). Full suite under
-raceon both backends, TLS tests 5× each; staticcheck clean.🤖 Generated with Claude Code