WIP: ipc: stop listeners in CapnpProtocol::disconnectIncoming() #37009

Draft
mutatrum wants to merge 2 commits from fix/ipc-stop-listeners-36585 into master AGit
mutatrum commented 2026-11-29 16:28:21 +00:00 (Migrated from github.com)

Related: #36585.

Depends on bitcoin-core/libmultiprocess#403 (fixes bitcoin-core/libmultiprocess#385).

Note: The first commit ([DO NOT MERGE]) temporarily mirrors the libmultiprocess PR in src/ipc/libmultiprocess/include/mp/proxy-io.h so CI can build and test this branch. It will be dropped once libmultiprocess merges and is subtree-synced.

Motivation

During Shutdown(), disconnectIncoming() closes existing IPC connections but leaves the listening socket open and present on disk. Auto-reconnecting IPC clients (such as mining clients like sv2-tp or ckpool) can reconnect in this window, acquiring a new EventLoopRef and causing ~CapnpProtocol() to hang indefinitely waiting for the reconnected client (#36585).

Change

src/ipc/capnp/protocol.cpp: Store the std::shared_ptr<mp::Listener> handles returned by mp::ListenConnections() in CapnpProtocol::m_listeners, and stop/clear them on m_loop->sync at the start of disconnectIncoming() (before removing existing m_incoming_connections) and in ~CapnpProtocol().

Related: #36585. Depends on bitcoin-core/libmultiprocess#403 (fixes bitcoin-core/libmultiprocess#385). > **Note:** The first commit (`[DO NOT MERGE]`) temporarily mirrors the `libmultiprocess` PR in `src/ipc/libmultiprocess/include/mp/proxy-io.h` so CI can build and test this branch. It will be dropped once `libmultiprocess` merges and is subtree-synced. #### Motivation During `Shutdown()`, `disconnectIncoming()` closes existing IPC connections but leaves the listening socket open and present on disk. Auto-reconnecting IPC clients (such as mining clients like `sv2-tp` or `ckpool`) can reconnect in this window, acquiring a new `EventLoopRef` and causing `~CapnpProtocol()` to hang indefinitely waiting for the reconnected client (#36585). #### Change **`src/ipc/capnp/protocol.cpp`**: Store the `std::shared_ptr<mp::Listener>` handles returned by `mp::ListenConnections()` in `CapnpProtocol::m_listeners`, and stop/clear them on `m_loop->sync` at the start of `disconnectIncoming()` (before removing existing `m_incoming_connections`) and in `~CapnpProtocol()`.
DrahtBot commented 2026-11-29 16:28:32 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36572 (ipc: hold event loop references when using it in CapnpProtocol by nullfail)
  • #35932 (ipc: make ipc::disconnectIncoming wait for in-progress calls to complete by ryanofsky)
  • #32387 (ipc: add windows support by ryanofsky)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37009 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37009.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37009#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36572](https://github.com/bitcoin/bitcoin/pull/36572) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36572.svg"></sub> (ipc: hold event loop references when using it in `CapnpProtocol` by nullfail) * [#35932](https://github.com/bitcoin/bitcoin/pull/35932) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35932.svg"></sub> (ipc: make ipc::disconnectIncoming wait for in-progress calls to complete by ryanofsky) * [#32387](https://github.com/bitcoin/bitcoin/pull/32387) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32387.svg"></sub> (ipc: add windows support by ryanofsky) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · Reconnect test can pass without checking the listener stop in disconnectIncoming()

The reconnect assertion can pass after later teardown closes the socket, without verifying that disconnectIncoming() stopped listening.

Location: test/functional/interface_ipc.py:214 (head).

🔵 Suggestion · Listener tests miss explicit stop and retained-handle cancellation

Dedicated listener tests cover pause/resume but not explicit stop(), repeated stops, or loop cancellation while a caller retains the handle.

Location: src/ipc/libmultiprocess/include/mp/proxy-io.h:993 (head).


Reviewed: 50f952f9af3e · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afedb19cca4c3b40d89514fb0c66b0c20e4f5d62 --> <!-- ralph-head:50f952f9af3e065512593f7023351736720d5b34 --> <!-- ralph-case:cc4a9efedfe1551d9933f5eabd3bed635f3e7f5f2afbb53767ba6c6c57f93417 --> **🔵 Suggestion · Reconnect test can pass without checking the listener stop in `disconnectIncoming()`** The reconnect assertion can pass after later teardown closes the socket, without verifying that `disconnectIncoming()` stopped listening. Location: [`test/functional/interface_ipc.py:214`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/50f952f9af3e065512593f7023351736720d5b34/test/functional/interface_ipc.py#L214>) (head). **🔵 Suggestion · Listener tests miss explicit stop and retained-handle cancellation** Dedicated listener tests cover pause/resume but not explicit `stop()`, repeated stops, or loop cancellation while a caller retains the handle. Location: [`src/ipc/libmultiprocess/include/mp/proxy-io.h:993`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/50f952f9af3e065512593f7023351736720d5b34/src/ipc/libmultiprocess/include/mp/proxy-io.h#L993>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`50f952f9af3e`](<https://git.fish.foo/bitcoin/bitcoin/commit/50f952f9af3e065512593f7023351736720d5b34>) · [Review report](<https://review.fish.foo/report/37009-50f952f9af3e065512593f7023351736720d5b34-3327-7.html>) · [Previous reports](<https://review.fish.foo/traces/37009/>) [permalink](<https://review.fish.foo/report/37009-50f952f9af3e065512593f7023351736720d5b34-3327-7.html>)
DrahtBot commented 2026-11-29 17:33:08 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task macOS native: https://github.com/bitcoin/bitcoin/actions/runs/46285602934/job/141417498195
LLM reason (✨ experimental): functional_test_fail: The functional test interface_ipc_cli.py failed; the other listed tests passed or were skipped.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.

  • A functional or integration test failure may be intermittent or unrelated to this pull request.
    If no dedicated issue thread exists, create a new one to track it.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `macOS native`: https://github.com/bitcoin/bitcoin/actions/runs/46285602934/job/141417498195</sub> <sub>LLM reason (✨ experimental): functional_test_fail: The functional test `interface_ipc_cli.py` failed; the other listed tests passed or were skipped.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening. * A functional or integration test failure may be intermittent or unrelated to this pull request. If no dedicated issue thread exists, create a new one to track it. Leave a comment here, if you need help tracking down a confusing failure. </details>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37009
No description provided.