Repository navigation
fix(Silk): honor O_NONBLOCK in the fiber TLS BIO - #111852
Conversation
silkBioRead/silkBioWrite always submitted io_uring I/O and parked the caller for the socket's send/receive timeout, ignoring the fd's O_NONBLOCK flag. The HTTP connection pool's staleness probe (getSslSocketState -> SSL_peek) sets the fd non-blocking and expects an immediate EAGAIN; with the silk BIO it instead blocked for the timeout left on the socket by the previous request. Every pooled-connection borrow then paid that timeout - a server loading tables from an HTTPS object-store disk at startup stalls (a deterministic 13.5s here, an unbounded boot hang with production timeouts). When the fd is non-blocking, do a direct recv/send with MSG_DONTWAIT and set the BIO retry flags; the fiber path is unchanged for blocking sockets. Adds a regression test asserting the non-blocking peek returns promptly on an idle TLS connection.
|
Workflow [PR], commit [6a5cb11] Summary: ❌
AI ReviewSummaryThis PR teaches the silk TLS BIO to honor the temporary non-blocking probe used by Tests
Final VerdictChanges requested: add focused coverage for the write-side non-blocking BIO path before merge. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 135/151 (89.40%) · Uncovered code |
A lower-level companion to NonBlockingPeekDoesNotBlockOnIdleConnection: drives SSL_peek directly on a non-blocking silk TLS socket - no getSocketState / connection-pool helper - and asserts it returns SSL_ERROR_WANT_READ in under 500ms, one level below the pool's staleness probe that the other test exercises.
| /// since silk sockets reject `Socket::setBlocking(false)`, so O_NONBLOCK is set on the raw fd | ||
| /// directly and only OpenSSL's BIO (`silkBioRead`) ever observes it. Pre-fix, `silkBioRead` | ||
| /// ignores the flag and parks the caller for the full receive timeout. | ||
| TEST_F(SilkFiberSecureSocketTest, NonBlockingSslPeekReturnsWantReadImmediately) |
There was a problem hiding this comment.
Both added regressions only prove the SSL_peek -> SSL_ERROR_WANT_READ path. This PR also changes silkBioWrite, and getSslSocketState already treats SSL_ERROR_WANT_WRITE as a real outcome because SSL_peek can hit it while processing post-handshake traffic such as KeyUpdate.
Without one focused case that actually drives SSL_peek into WANT_WRITE, a regression in the new write-side O_NONBLOCK branch will still leave the pool probe hanging while these tests stay green. Please add a secure-socket test that forces the write side and asserts the call returns quickly instead of waiting for getSendTimeout().
|
@CheSema, PTAL: 26eb7ab, 33366b7. Arguably, setting the raw socket to blocking instead of calling And for silk sockets, it's cleaner to explicitly call |
Resolved a conflict in src/IO/SocketPeerClosed.cpp: master renamed `getSslSocketState` to `getSSLSocketState` while this branch restructured the secure-socket probe (silk `setDontWait` branch + Poco-based `ScopedNonBlocking`); kept the branch structure with master's names. Co-Authored-By: Claude Fable 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 127/143 (88.81%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units9 translation units recompiled, 9 s compile time in total, 8 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
This is a latent-interaction bug that appears only when three components are combined — none is wrong on its own:
silkBioRead/silkBioWritesubmits io_uring I/O and parks the caller for the socket's send/receive timeout. That is correct for a blocking read — but the BIO never consults the fd'sO_NONBLOCKflag, unlike OpenSSL's default socket BIO, which returnsEAGAINimmediately when the flag is set.USE_SSL): the affected path is the TLS BIO. The plain-socket staleness check uses a rawrecv(MSG_PEEK | MSG_DONTWAIT)and never touches this code, so the problem is TLS-only.SSL_peekstaleness probe (Detect HTTP keep-alive peer disconnect with MSG_PEEK/SSL_peek, not poll #110402): before reusing a pooled connection,DB::getSocketStateflips the fd non-blocking viaScopedNonBlocking(a rawfcntl(F_SETFL, O_NONBLOCK), behind Poco's back) and callsSSL_peek, expecting an immediateEAGAIN— its comment reads "The socket is non-blocking, so this never blocks." Detect HTTP keep-alive peer disconnect with MSG_PEEK/SSL_peek, not poll #110402 introduced this probe, replacing the previouspoll-based keep-alive disconnect check.Only with all three present does that non-blocking
SSL_peekroute through the silk BIO, which ignoresO_NONBLOCKand blocks for the receive timeout left on the socket by the previous request. Each component is individually correct; the fix lands on the silk BIO because it is the one whose behavior diverges from OpenSSL's socket-BIO contract (honoringO_NONBLOCK), while the TLS layer and the#110402probe are behaving as intended.On
mastertoday the silk BIO has no wired production consumer — it is infrastructure — so this three-way combination is not yet reachable in a shipped server; it was reproduced with downstream work that routes object-storage-disk connections through silk fiber sockets.Impact. Every borrow of a pooled TLS connection to an object-storage disk pays a timeout it should not. A server loading tables from an HTTPS object-store disk at startup does many such borrows and stalls — a deterministic ~13.5 s in a local reproduction, and an unbounded boot hang (never reaching "Ready for connections", no error logged) with production timeouts or a zero/unset receive timeout, where the wait becomes a deadline-less
future.wait().Root-cause evidence (local TLS-MinIO reproduction): a server-side request trace showed each request arriving only after its wait expired; the ~13.5 s decomposed exactly into the adaptive per-method receive timeouts paid in sequence (GET 500 ms + PUT 3000 ms + DELETE 10000 ms,
ConnectionTimeouts.cpp);ssshowed frozenbytes_sentthrough each stall; and a live backtrace was parked atsilkBioRead←SSL_peek←getSslSocketState←isStale←getConnection. A control with silk sockets disabled does the same step in <15 ms. The plain-HTTP staleness probe uses a rawrecv(MSG_PEEK|MSG_DONTWAIT)and is unaffected — the bug is TLS-specific.Fix. When the fd is non-blocking,
silkBioRead/silkBioWritedo a directrecv/sendwithMSG_DONTWAITand set the BIO retry flags (immediateEAGAIN→SSL_ERROR_WANT_READ), matching OpenSSL's default BIO. The fiber/io_uring path is unchanged for blocking sockets. The non-blocking state is read fresh from the fd on each call viafcntl(F_GETFL), becausePoco::Net::SocketImpl::getBlocking()is a cached flag the raw-fcntlprobe never updates (and silk sockets rejectsetBlocking(false)outright).Adds a regression test (
SilkFiberSecureSocketTest.NonBlockingPeekDoesNotBlockOnIdleConnection) that drives the realgetSocketStatepath against an idle TLS connection with a 5 s receive timeout and asserts it returns in under 500 ms; without the fix it blocks the full timeout.Not for changelog: the silk fiber BIO is infrastructure with no in-tree production consumer yet, so no released user is affected.
Related: #107680
Related: #110402