type-context.h: Extent cancel_mutex lock to prevent theoretical race #245

pull ryanofsky wants to merge 2 commits into bitcoin-core:master from ryanofsky:pr/cancelmutex changing 2 files +3 −3
  1. ryanofsky commented at 8:19 pm on February 24, 2026: collaborator
    This is a followup to #240 that fixes a theoretical race condition in that PR pointed out by janb https://github.com/bitcoin/bitcoin/pull/34422#discussion_r2849037119. Details are in the commit message. There is also an additional commit fixing up some documentation added in that PR
  2. type-context.h: Extent cancel_mutex lock to prevent theoretical race
    As pointed out by janb84 in
    https://github.com/bitcoin/bitcoin/pull/34422#discussion_r2849037119 it makes
    sense for the on_cancel callback to lock cancel_mutex while it is assigning
    request_canceled = true.
    
    The lock and assigment were introduced in #240 and in an earlier version of
    that PR, request_canceled was a std::atomic and the assignment happened before
    the lock was acquired instead of after, so it was ok for the lock to be unnamed
    and immediately released after being acquired.
    
    But in the final verion of #240 request_canceled is an ordinary non-atomic
    bool, and it should be assigned true with the lock held to prevent a
    theoretical race condition where capn'proto event loop cancels the request
    before the execution thread runs, and the execution thread sees the old
    request_canceled = false value and then unsafely accesses deleted parameters.
    The request being canceled so quickly and parameters being accessed so slowly,
    and stale request_canceled value being read even after the execution thread has
    the cancel_mutex lock should be very unlikely to occur in practice, but could
    happen in theory and is good to fix.
    e0f1cd7621
  3. doc: Comment cleanups after #240 ef96a5b2be
  4. DrahtBot commented at 8:19 pm on February 24, 2026: none

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. Sjors commented at 3:09 pm on February 25, 2026: member
    ACK ef96a5b2be2f35ef09c19a5ff4a113144c596309
  6. ryanofsky merged this on Feb 25, 2026
  7. ryanofsky closed this on Feb 25, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-09 11:30 UTC

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