Skip to content

epoll fallback, TLS, English comments and architecture doc (roadmap 5, 14, 22) - #30

Merged
y001j merged 3 commits into
masterfrom
feat/epoll-tls
Nov 22, 2026
Merged

y001j merged 3 commits into
masterfrom
feat/epoll-tls

Conversation

@y001j

@y001j y001j commented Nov 22, 2026

Copy link
Copy Markdown
Owner

epoll fallback (item 5)

  • Event loops run on an internal eventLoop interface: io_uring (iouring-go) and a new epoll backend that emulates multishot accept/recv/recvmsg, the provided-buffer pool (LIFO; -ENOBUFS when empty), send retry on EPOLLOUT, 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 with kernel.io_uring_disabled=2 (this caught a bug in the first fallback check). Server.Backend().
  • The whole test suite passes on both backends (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. OnOpen after the handshake; Close sends close_notify.
  • Handshake on a goroutine; afterwards decryption/encryption on the loop thread (the transport returns a temporary net.Error for incomplete records, which crypto/tls tolerates after the handshake — checked in Go 1.22 and 1.27 sources).
  • vs a crypto/tls server (1 core): 0.93–1.24x at 128B, 0.8x at 16KB. The first version (decrypting goroutine) was 0.33–0.42x.

English comments and architecture (item 22)

  • All Go comments (library, tests, examples, bench) in English; an AST comparison confirmed only comments changed.
  • 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 -race on both backends, TLS tests 5× each; staticcheck clean.

🤖 Generated with Claude Code

y001j and others added 3 commits November 22, 2026 21:42
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

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.54890% with 136 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.13%. Comparing base (7dfab1a) to head (96753bc).

Files with missing lines Patch % Lines
epoll.go 71.70% 88 Missing ⚠️
tls.go 85.71% 21 Missing ⚠️
backend.go 84.09% 7 Missing ⚠️
connection.go 84.09% 7 Missing ⚠️
uringnet.go 83.72% 7 Missing ⚠️
dial.go 85.71% 3 Missing ⚠️
codec.go 0.00% 1 Missing ⚠️
conn.go 80.00% 1 Missing ⚠️
udp.go 85.71% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@y001j
y001j merged commit c8b7ab1 into master Nov 22, 2026
6 checks passed
@y001j
y001j deleted the feat/epoll-tls branch November 22, 2026 13:04
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