depends: fix IPC listeners on macOS dying when accepting a dead socket #35796

pull xyzconstant wants to merge 1 commits into bitcoin:master from xyzconstant:depends-capnp-macos-einval changing 2 files +35 −0
  1. xyzconstant commented at 12:22 AM on July 25, 2026: contributor

    This PR adds a depends patch to fix a Cap'n Proto bug present in macOS that throws the following exception after accepting a disconnected client:

    mp/proxy.cpp:48: error: Uncaught exception in daemonized task.; exception = kj/async-io-unix.c++:1365: failed: setsocketopt(IPPROTO_TCP, TCP_NODELAY): Invalid argument
    

    This goes uncaught killing libmultiprocess's accept loop (mp::ListenConnections()) in the process.

    Root cause

    After accept(), kj unconditionally calls setsockopt(TCP_NODELAY) on the connection socket. For Unix sockets, kj handles the usual "not supported" error codes, however, on macOS EINVAL is returned when the client has already disconnected and kj only tolerates that code when built for FreeBSD. The unexpected error then goes uncaught in the accept loop, causing the listener to stop accepting new connections.

    See https://github.com/bitcoin-core/libmultiprocess/issues/319 for more details and instructions on how to reproduce it in Bitcoin Core using socat.

    Fix

    The patch is based on the EINVAL handling from capnproto/capnproto@7df5bd078, which is only available on the not yet released v2 branch. It's applied to capnp.mk as a temporary workaround until capnproto/capnproto#2748 is available in a v1 release.

    <!-- *** Please remove the following help text before submitting: *** Pull requests may be closed immediately if they: - do not have a rationale and clear improvement - do not adhere to doc/AI_POLICY.md GUI-related pull requests should be opened against https://github.com/bitcoin-core/gui first. See CONTRIBUTING.md -->

    <!-- Please provide clear motivation for your patch and explain how it improves Bitcoin Core user experience or Bitcoin Core developer experience significantly: * Any test improvements or new tests that improve coverage are always welcome. * All other changes should have accompanying unit tests (see `src/test/`) or functional tests (see `test/`). Contributors should note which tests cover modified code. If no tests exist for a region of modified code, new tests should accompany the change. * Bug fixes are most welcome when they come with steps to reproduce or an explanation of the potential issue as well as reasoning for the way the bug was fixed. * Features are welcome, but might be rejected due to design or scope issues. If a feature is based on a lot of dependencies, contributors should first consider building the system outside of Bitcoin Core, if possible. * Refactoring changes are only accepted if they are required for a feature or bug fix or otherwise improve developer experience significantly. For example, most "code style" refactoring changes require a thorough explanation why they are useful, what downsides they have and why they *significantly* improve developer experience or avoid serious programming bugs. Note that code style is often a subjective matter. Unless they are explicitly mentioned to be preferred in the [developer notes](/doc/developer-notes.md), stylistic code changes are usually rejected. -->

    <!-- Bitcoin Core has a thorough review process and even the most trivial change needs to pass a lot of eyes and requires non-zero or even substantial time effort to review. There is a huge lack of active reviewers on the project, so patches often sit for a long time. -->

  2. depends: fix IPC listeners on macOS dying when accepting a dead socket
    After `accept()`, kj unconditionally calls `setsockopt(TCP_NODELAY)` on the
    connection socket. For Unix sockets, kj handles the usual "not supported"
    error codes, however, on macOS EINVAL is returned when the client has already
    disconnected and kj only tolerates that code when built for FreeBSD.
    The unexpected error then goes uncaught in the accept loop, causing the
    listener to stop accepting new connections.
    
    See https://github.com/bitcoin-core/libmultiprocess/issues/319 for more details.
    
    Patch based on the EINVAL handling from https://github.com/capnproto/capnproto/commit/7df5bd078.
    6da460d784
  3. DrahtBot added the label Build system on Jul 25, 2026
  4. DrahtBot commented at 12:22 AM on July 25, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35796.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. hebasto commented at 7:33 AM on July 25, 2026: member

    Is there a related upstream issue?

  6. xyzconstant commented at 3:57 PM on July 25, 2026: contributor

    re: #35796#pullrequestreview-4778841077

    There's this one I opened in libmultiprocess https://github.com/bitcoin-core/libmultiprocess/issues/319

  7. Sjors commented at 10:47 AM on July 27, 2026: member

    This is a patch to capnp.mk‎, so "upstream" means capnpp here. My understanding from https://github.com/bitcoin-core/libmultiprocess/issues/319 is that it's been fixed in v2, but not back-ported (yet) to v1.

  8. hebasto commented at 11:01 AM on July 27, 2026: member

    This is a patch to capnp.mk‎, so "upstream" means capnpp here.

    Exactly.

    My understanding from bitcoin-core/libmultiprocess#319 is that it's been fixed in v2, but not back-ported (yet) to v1.

    Based on the EINVAL handling from https://github.com/capnproto/capnproto/commit/7df5bd078

    Upstream https://github.com/capnproto/capnproto/commit/7df5bd078 has a much larger diff than the patch in this PR. Because of this, it would be good to see a PR that backports the fix to the master branch in capnproto/capnproto first.

  9. xyzconstant commented at 6:27 PM on July 27, 2026: contributor

    This is a patch to capnp.mk‎, so "upstream" means capnpp here. My understanding from bitcoin-core/libmultiprocess#319 is that it's been fixed in v2, but not back-ported (yet) to v1.

    Oh thanks for the clarification.

  10. xyzconstant commented at 6:37 PM on July 27, 2026: contributor

    This is a patch to capnp.mk‎, so "upstream" means capnpp here.

    Exactly.

    Sorry, I got it wrong. As @Sjors said, it's only merged in v2. There wasn't an issue or PR in there backporting it to v1.

    My understanding from bitcoin-core/libmultiprocess#319 is that it's been fixed in v2, but not back-ported (yet) to v1.

    Based on the EINVAL handling from capnproto/capnproto@7df5bd078

    Upstream capnproto/capnproto@7df5bd078 has a much larger diff than the patch in this PR. Because of this, it would be good to see a PR that backports the fix to the master branch in capnproto/capnproto first.

    I just opened capnproto/capnproto#2748, which backports the complete upstream commit and is not as minimal as the depends patch in this PR (only the EINVAL check).

  11. xyzconstant commented at 8:26 PM on July 28, 2026: contributor

    I just opened capnproto/capnproto#2748, which backports the complete upstream commit and is not as minimal as the depends patch in this PR (only the EINVAL check).

    The backport has just been merged on upstream.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-31 20:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me