Repository navigation
Conversation
… sockets Step 2 of #131084. One thread can send and watch for data at the same time without blocking. A send error is held until the caller has read what arrived, so a response sent before a reset is not lost. Plain TCP only; TLS sockets and the wait of Silk fiber sockets throw until steps 3 and 4.
|
Workflow [PR], commit [425f75b] Summary: ✅
AI ReviewSummaryAdds non-blocking socket operations for plain TCP, TLS, and Silk, with deferred send errors and a bounded TLS ciphertext queue. The current code addresses the previous findings. No remaining actionable correctness or safety issue was found. Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
…ceive` for TLS sockets Step 3 of #131084. A filter BIO, installed by the first non-blocking call, queues the encrypted bytes that do not fit and holds a transport send error, so OpenSSL never has a pending or failed write and `SSL_read` stays allowed. Blocking calls pass through as before, after the queued bytes.
Step 4 of #131084. The wait suspends the fiber through `FiberScheduler::poll`, not the thread. Silk TLS sockets get the non-blocking calls through the filter BIO of step 3, on top of their `silk-fiber` BIO.
The callers keep the queue within one record and a few control records; the limit does not depend on that. A write over it fails the connection: a retry would leave OpenSSL with a pending write. No test: no real TLS peer can grow the queue past one record and its control records.
sendNow, receiveNow and waitForSendOrReceive to socketssendNow, receiveNow and waitForSendOrReceive to plain, TLS and Silk sockets
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes55 object files changed (+99.35 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1818 translation units recompiled, 3400 s compile time in total, 1817 of them have a recent master baseline. |
A throttler wait inside a BIO callback can suspend a Silk fiber in the middle of an OpenSSL call, and the fiber can resume on another thread with another error queue. `SecureSocketImpl::sendNow` now waits before `SSL_write` and books the plaintext bytes, as `sendBytes` does; the filter sends with `sendNowUnthrottled`.
…OpenSSL The wait sends the queued ciphertext also when the caller waits only for data, and a blocking receive uses `receiveNow` and the wait while bytes are queued. So a failed write of the queue never reaches OpenSSL, and an answer that has arrived is read even if the peer does not read any more. The blocking read of the filter no longer writes the queue.
OpenSSL takes a zero read for the end of the stream only when `BIO_eof` is true. The non-blocking read of the filter now sets `BIO_FLAGS_IN_EOF`, so `receiveNow` returns -1, as a blocking receive does.
AI review of a later commit does not approve the PR, see the AI Review comment.
TLS `receiveNow` books the plaintext before `SSL_read` and uses the returned bytes, as `receiveBytes` does, and the filter reads with `receiveNowUnthrottled`. A throttler error no longer fails the TLS connection, and the blocking fallback of `receiveBytes` settles its booked budget.
| /// While a non-blocking send has left queued bytes, the receive uses the non-blocking calls, and | ||
| /// the wait sends the bytes outside OpenSSL: OpenSSL must not see their failed write, and a peer | ||
| /// that has answered is read even if it does not read any more. | ||
| if (_pSocket->getBlocking() && (flags & MSG_DONTWAIT) == 0) |
There was a problem hiding this comment.
AI findings:
The description no longer matches the TLS code. Update the TLS bullet and the last sentence.
- "Blocking calls pass through as before, after the queued bytes" is now true only for blocking sends. While bytes are queued, a blocking
receiveBytesusesreadNowandwaitForSendOrReceivehere, and the blockingreadof the filter no longer sends the queue first. - The TLS non-blocking calls now throttle the plaintext outside OpenSSL, and the filter sends and receives through
sendNowUnthrottledandreceiveNowUnthrottled. The description does not say this. - "One commit for each socket type, and one for the queue limit" no longer matches the 15 commits.
| bool queued = false; | ||
| { | ||
| NonBlockingFilterBIO::NonBlockingScope scope(filter); | ||
| queued = !filter.sendQueued(); | ||
| } |
There was a problem hiding this comment.
AI findings:
nit: this NonBlockingScope does nothing. sendQueued calls sendNowUnthrottled directly, and only the BIO callbacks look at the mode. The scope makes the reader look for a dependency on the mode that does not exist.
| bool queued = false; | |
| { | |
| NonBlockingFilterBIO::NonBlockingScope scope(filter); | |
| queued = !filter.sendQueued(); | |
| } | |
| const bool queued = !filter.sendQueued(); |
| int writeNonBlocking(const char * data, int length); | ||
| int readNonBlocking(BIO * bio, char * data, int length); | ||
|
|
||
| int writeQueuedToNext(BIO * bio); |
There was a problem hiding this comment.
Maybe writeQueuedBlocking?
I don't have a strong opinion here
| ScopedLock lock(*_mutex); | ||
| if (length <= 0) | ||
| throw InvalidArgumentException("receiveNow needs a positive length"); |
There was a problem hiding this comment.
AI findings:
nit: check length before the lock, as waitForSendOrReceive now does with mode (line 576). With two orders in one class, the reader looks for a reason why they differ, and there is none. sendNow has the same order (line 624).
| ScopedLock lock(*_mutex); | |
| if (length <= 0) | |
| throw InvalidArgumentException("receiveNow needs a positive length"); | |
| if (length <= 0) | |
| throw InvalidArgumentException("receiveNow needs a positive length"); | |
| ScopedLock lock(*_mutex); |
| ScopedLock lock(*_mutex); | ||
| if (length <= 0) | ||
| throw InvalidArgumentException("sendNow needs a positive length"); |
There was a problem hiding this comment.
AI findings:
nit: the same as in receiveNow: check length before the lock.
| ScopedLock lock(*_mutex); | |
| if (length <= 0) | |
| throw InvalidArgumentException("sendNow needs a positive length"); | |
| if (length <= 0) | |
| throw InvalidArgumentException("sendNow needs a positive length"); | |
| ScopedLock lock(*_mutex); |
Steps 2 to 4 of #131084: non-blocking socket primitives for plain TCP, TLS and Silk fiber sockets. No behavior change and no caller yet; step 5 uses them in the HTTP body writer.
Poco::Net::SocketImplgetswaitForSendOrReceive,sendNowandreceiveNow. With them, one thread sends data and watches for data from the peer at the same time, and nothing blocks. A connection error ofsendNowis held until the caller has read what arrived, so a response that the server sent before a reset is not lost. A check before the send cannot close this window: #131102 (comment).MSG_DONTWAIT, and the socket holds the error of a failed send.SSL_ERROR_WANT_WRITE, or after a failed transport write, OpenSSL allows noSSL_read. The first non-blocking call pushesNonBlockingFilterBIOon top of the transport BIO. In the non-blocking calls, the filter sends and receives through the primitives of the transport socket. It queues what does not fit, and it drops the bytes after a send error, which the transport socket holds. So OpenSSL never has a pending or a failed write.sendNowgivesSSL_writeone record at a time, and only when the queue is empty; the queue has a hard limit of 64 KiB. Blocking calls pass through as before, after the queued bytes.FiberScheduler::poll, not the thread. Silk TLS sockets use the same filter on top of theirsilk-fiberBIO.One commit for each socket type, and one for the queue limit.
Related: #131084
Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132376]