sock: align exception monitoring between poll() and select() backends #36665

pull darosior wants to merge 1 commits into bitcoin:master from darosior:2610_sock_select_poll changing 1 files +4 −2
  1. darosior commented at 1:59 PM on October 26, 2026: member

    On non-Linux platforms, WaitMany monitors every socket for exceptional conditions, even when we are not looking to read from it. On Linux, it never monitors those.

    Monitoring for certain socket events on some platforms but not others is inconsistent and surprising. In this instance it probably means these cases receive less testing as well, since they are ignored on our most well-tested platform.

    Fix this issue by only monitoring for exceptional conditions (which is necessary to detect failed connection attempts early on Windows) for sockets we are also waiting to read from.

  2. sock: align exception monitoring between poll() and select() backends 1e0c407377
  3. DrahtBot commented at 1:59 PM on October 26, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK vasild, sedited, instagibbs, pinheadmz

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/util/sock.cpp:223 in 1e0c407377
     215 | @@ -216,12 +216,14 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
     216 |          const auto& s = sock->m_socket;
     217 |          if (events.requested & RecvEvent) {
     218 |              FD_SET(s, &recv);
     219 | +            FD_SET(s, &err);
     220 |          }
     221 |          if (events.requested & SendEvent) {
     222 |              FD_SET(s, &send);
     223 |          }
     224 | -        FD_SET(s, &err);
    


    vasild commented at 2:50 PM on October 26, 2026:

    Just a note to other reviewers: it looks fine to just drop FD_SET(s, &err); instead of moving it to under if (events.requested & RecvEvent). We do not expect and do not care about any "exceptional conditions":

    from select(2):

    exceptfds
           The  file  descriptors  in this set are watched for "exceptional conditions".  For examples of some excep‐
           tional conditions, see the discussion of POLLPRI in poll(2).

    from poll(2):

     POLLPRI
           There is some exceptional condition on the file descriptor.  Possibilities include:
           •  There is out-of-band data on a TCP socket (see tcp(7)).
           •  A pseudoterminal master in packet mode has seen a state change on the slave (see ioctl_tty(2)).
           •  A cgroup.events file has been modified (see cgroups(7)).

    Also, our poll() branch does not do POLLPRI.

    However! https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select:

    exceptfds: If processing a connect call (nonblocking), connection attempt failed. OOB data is available for reading (only if SO_OOBINLINE is disabled).

    So, FD_SET(s, &err); is needed on Windows to handle our non-blocking connect()s.

  5. vasild approved
  6. vasild commented at 3:08 PM on October 26, 2026: contributor

    ACK 1e0c407377034e9cbb4d52f1f534c06cdf202a36

    Indeed the poll(2) and select(2) branches seem to be inconsistent.

    Thanks!

  7. sedited approved
  8. sedited commented at 3:17 PM on October 26, 2026: contributor

    utACK 1e0c407377034e9cbb4d52f1f534c06cdf202a36

  9. instagibbs approved
  10. instagibbs commented at 3:41 PM on October 26, 2026: member

    ACK 1e0c407377034e9cbb4d52f1f534c06cdf202a36

    Validated a prefinal form in freebsd

  11. pinheadmz approved
  12. pinheadmz commented at 3:55 PM on October 26, 2026: member

    ACK 1e0c407377034e9cbb4d52f1f534c06cdf202a36

    built and tested on macos/arm64, clauded up a test that send an "exceptional" byte on master and compared to branch. Came to same conclusions as vasild in https://github.com/bitcoin/bitcoin/pull/36665/changes#r4378669650

    This is a clean solution to the discrepency

    <details><summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 1e0c407377034e9cbb4d52f1f534c06cdf202a36
    -----BEGIN PGP SIGNATURE-----
    
    iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmrfd18bFIAAAAAABAAO
    bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6ZDoP/2oRg7qiKLHVahwfPfyd
    TktDRlqitdF0hhqRtUPwTFJ5M2X14pM5bSEKf67B+FprjdSDfAGLmwm59QCsAyMJ
    FB/8+9KvGuYKt4V3S18LjNskPTzS9sjx/sb2QJsjNFnvl366XhYQnKe9awA/JHsg
    FPg1slp035Z0+qikkwvqtPMIGi+ZGwh0+RAAn46rvjIb0NP2KF4tpTnmfwPr87QK
    vlSCDm7bBN1OpnAy1dc0SqUATl3g12YJiSNQdOCsN9clJv/P3c9Fb3yjg3uNdY2B
    N0+y/NGyYWI6XNimIK9DDaz9kzQCjd2P4XniUm074VHFZODuA1CsyZsuPr7oebkO
    XFvBr4Y72ErrlCmpuquM1rtgbkIXrw4mKwc+W0YOmEYTPx1TxT91mtkV/Za/zTk3
    XCpPl4sCCeE2RGVDdvNgijIcjvNT9lnZIktM8cqMkP7vPapWoUslQ/1iOb/2PPGM
    hMWJ77+Htlpu1FNL7/HKhbkEsaUOY0a8r+wgqenhjHV1hihi+M0TbNdLrj0sQxz6
    IQv3JWk6vq1aA32y+aPahM6v1EJl7qLcjkTMaQtMzM13KW9fakPZeyzqtXP0MLAX
    D74B1n2M+f205gx+Kg6xZg0xxNsrEbKbG743yZn6U6axMZoP98zmiX37A0iDPpaM
    RjTHsecfylVeKOEfff91uw2J
    =/uZl
    -----END PGP SIGNATURE-----
    

    pinheadmz's public key is on openpgp.org

    </details>

  13. fanquake merged this on Oct 26, 2026
  14. fanquake closed this on Oct 26, 2026

  15. fanquake referenced this in commit d7915a18de on Oct 26, 2026
  16. fanquake commented at 4:08 PM on October 26, 2026: member

    Backported to 32.x in #36658.

  17. darosior deleted the branch on Oct 26, 2026
  18. fanquake commented at 4:17 PM on October 26, 2026: member

    Backported to 31.x in #36661.

  19. fanquake referenced this in commit 9918ecdc06 on Oct 26, 2026
  20. fanquake referenced this in commit d4a065bf0f on Oct 26, 2026
  21. fanquake commented at 4:25 PM on October 26, 2026: member

    Backported to 30.x in #36664.

  22. fanquake commented at 4:25 PM on October 26, 2026: member

    Backported to 29.x in #36666.

  23. fanquake referenced this in commit b3526cf152 on Oct 26, 2026
  24. fanquake referenced this in commit a4b4cefc14 on Oct 26, 2026

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-10-26 20:51 UTC

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