Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
f0fb4e9 to
957c3e2
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Code review 957c3e2. Concept ACK, and thanks for picking up #385. The approach looks right to me: returning the listener, cancelling the accept by destroying its task set, closing the socket so backlogged clients are dropped, and the guard that calls stop() if the event loop exits first all fit together, and the return type change keeps Bitcoin Core compiling unchanged. The suggestions below are mostly simplifications, plus one test addition.
Thanks also for opening the Bitcoin Core side in bitcoin/bitcoin#37009. This touches the same accept loop as #361, so whichever merges second will need a rebase, and the stop logic should be rechecked then.
Return std::shared_ptr<Listener> from ListenConnections() with stop() and stopped() methods so callers can stop accepting new connections and close the listening socket on the event loop thread without disconnecting already-accepted clients (bitcoin-core#385). Run accept() promises in a dedicated kj::TaskSet on Listener so stop() can cancel pending accepts immediately, capture weak_ptr<Listener> in _Listen() callbacks to avoid reference cycles, and attach a kj::defer teardown guard to EventLoop::m_task_set so Listener::stop() runs if the event loop shuts down first. Also close the listening socket immediately if accept() fails with an error, rather than leaving it open without accepting while other connections remain active (bitcoin-core#384). Add unit tests for stopping an active listener and stopping while at the max_connections limit, including verifying that a backlogged client sees a disconnect.
957c3e2 to
fa1ac8b
Compare
|
Processed all review comments, thank you! There's a lot of finesse in properly handling closing, tricky to get it right. One addition: And the immediate "connection refused" handling, so this changeset is not dependent on #384. |
Return
std::shared_ptr<Listener>fromListenConnections()withstop()andstopped()methods so callers can stop accepting new connections and close the listening socket on the event loop thread without disconnecting already-accepted clients (#385).Run
accept()promises in a dedicatedkj::TaskSetonListenersostop()can cancel pending accepts immediately, captureweak_ptr<Listener>in_Listen()callbacks to avoid reference cycles, and attach a teardown guard toEventLoop::m_task_setsoListener::stop()runs if the event loop shuts down first.Add unit tests for stopping an active listener and stopping while at the
max_connectionslimit.Fixes: #385.
Related: bitcoin/bitcoin#36585.
Work-around in ckpool: https://git.mutatrum.com/mutatrum/ckpool/commit/0d2fe57b311ccfefb5059d8f01c6542c91b4bae1