Repository navigation
Closed
Description
Problem
After #1596 and #1606 two TLS read sites still issue a recv(2) that can only answer EAGAIN.
- Handshake read loop —
TlsHandshake::readable(lib/src/protocol/rustls.rs:151-159at7c820e57) callsread_tlsagain until it answersWouldBlock, even after arecvthat returned fewer bytes than the 4096 rustls offered (rustls-0.23.45/src/msgs/deframer/buffers.rs:208,220). After the ClientHello (≈1.5 KB) and after the clientFinished, rustls stillwants_read()(TLS 1.3 servers may send application data once their own flight is out), so each of these two short reads is followed by anEAGAIN. perf(socket): stop reading on a short read instead of reading until EAGAIN #1606 already stops the mux read path on a short read throughShortReadProbe(lib/src/socket.rs); the handshake does not use it. - Mux read of an established TLS session —
rustls_socket_read(lib/src/socket.rs:815at7c820e57), called from the H2readablepass (lib/src/protocol/mux/h2.rs:8314), still answersEAGAINalthough the records are ~100 bytes, so "a read that filled the 4096 bytes rustls offered" does not explain it. The mechanism has to be established before any change: anEAGAINbetween two calls, which perf(socket): stop reading on a short read instead of reading until EAGAIN #1606 kept on purpose because a new edge may arrive between them, or areadablecall made without a fresh event (a forced read, e.g. after the handshake upgrade).
Measurement (release, 7c820e57, one worker, loopback backend, 20 requests)
recv on the frontend TLS socket, LD_PRELOAD interposer with backtraces:
| scenario | handshake EAGAIN |
mux EAGAIN |
|---|---|---|
| H2, one connection per request (20 connections) | 37 (≈1.85 / connection) | ≈1.6 / connection |
| H2 multiplexed (1 connection, 20 requests) | — | ≈1.05 / request |
Prior art
- HAProxy drives the handshake with
SSL_do_handshakeand returns onSSL_ERROR_WANT_READ(src/ssl_sock.c,ssl_sock_handshake); its transport stops on a short read (src/raw_sock.c,fd_cant_recvwhenret < try). - tokio-rustls drives the handshake one
read_tlsper poll and returnsPendingonWouldBlock(tokio-rustls/src/common/handshake.rs).
Proposal
- Reuse
ShortReadProbein the handshake loop: stop after a shortrecv, drop READABLE, rely on the edge-triggered re-arm (same contract as perf(socket): stop reading on a short read instead of reading until EAGAIN #1606: HUP already seen ⇒ keep reading to EOF). A ClientHello split over several segments must still complete. - Establish the cause of (2) with symbolized backtraces and fix only that cause, without removing a legitimate wake-up.
Metadata
Metadata
Assignees
Labels
No labels
Activity
perf(tls): drop the EAGAIN recv of the handshake, its upgrade and spl…