Skip to content

Fix a run_loop future deadlock and an async_rw_mutex assertion - #8113

Merged
hkaiser merged 2 commits into
masterfrom
fix-run-loop-future-get
Nov 16, 2026
Merged

hkaiser merged 2 commits into
masterfrom
fix-run-loop-future-get

Conversation

@hkaiser

@hkaiser hkaiser commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

This fixes two problems that the review of the 2.0.1 cherry-picks in #8099 found in code from #7891 and #7907. The same code is on master, so the fixes go here first and are then picked for 2.0.1 (#8074).

  • run_loop futures (make_future.hpp): a future made by make_future with a run_loop scheduler marked its operation as finished only after it had made the future ready. Making the future ready runs the attached continuations, so a continuation that called get() on that future ran the loop until the operation was finished and waited forever for the receiver that was running it. 2.0.0 didn't have this problem; it came with Fix state machine race and deadlock in run_loop #7891. The receivers now mark the operation finished first. A waiter on another thread still waits in get() until the future is ready, and the receivers don't touch the loop after making the future ready.
  • async_rw_mutex (async_rw_mutex.hpp): if moving the value into the first shared state threw, the mutex kept that state without a value or an exception. Destroying the mutex then failed the assertion in the state's destructor (this was already the case in 2.0.0), and a later access got a state without a value. The state now gets the exception and is dropped, and the mutex is left as it was before the access.

Each fix comes with a regression test: test_run_loop_continuation_get (value, void and error, with the continuation attached through keep_future, as then() runs the loop first) and test_first_access_move_throw (read() and readwrite()). Without the fixes the first test hangs and the second fails the assertion. With them the affected execution tests (run_loop, both async_rw_mutex tests, make_future, sender_future_error, both as_sender tests) pass in a Debug build with MSVC 19.44, the run_loop and async_rw_mutex tests with 1 to 16 threads.

A future made by make_future with a run_loop scheduler marked its operation
as finished only after it had made the future ready. Making the future ready
runs the continuations attached to it, so a continuation that called get() on
that future ran the loop until the operation was finished, waiting for the
receiver that was running the continuation. Mark the operation finished
first; a waiter on another thread still waits in get() until the future is
ready.

Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
If moving the value into the first shared state threw, the mutex kept that
state without a value or an exception. Destroying the mutex then failed the
assertion in the state's destructor, and a later access got a state without
a value. Store the exception in the state, drop it and leave the mutex as it
was before the access.

Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
@hkaiser hkaiser added this to the 2.1.0 milestone Nov 15, 2026
@hkaiser hkaiser added type: defect category: senders/receivers Implementations of the p0443r14 / p2300 + p1897 proposals labels Nov 15, 2026
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Run-loop futures now complete their operations before notifying continuations, helping continuations that call get() finish reliably and observe results or exceptions.
    • The asynchronous read-write mutex now handles failures while moving its initial value more safely. Errors are reported to callers, and the mutex remains usable after a failed first access.
  • Tests
    • Added coverage for future continuations and for mutex recovery after an initial value move throws.

The changes update run-loop future completion ordering and async read-write mutex handling of exceptions during first access. Tests cover continuations that call get(), throwing initial-value moves, and later mutex access.

Changes: Run-loop future completion

Layer / File(s) Summary
Complete run-loop operations before forwarding
libs/core/execution/include/hpx/execution/algorithms/make_future.hpp, libs/core/execution/tests/unit/algorithm_run_loop.cpp
Both receiver forms complete the loop operation before forwarding value, error, or stopped completion. Tests cover value, void, and exception results when a keep_future continuation calls get().

Async read-write mutex first access

Layer / File(s) Summary
Handle exceptions during first access
libs/core/execution/include/hpx/synchronization/async_rw_mutex.hpp, libs/core/execution/tests/unit/async_rw_mutex_exception.cpp
First read and read-write access use move_value_to_first_state. The helper records and rethrows move exceptions after resetting state and restoring prev_access. The sender forwards stored state exceptions, and tests cover a subsequent successful access.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: shivansh023023

Merge Risk: Minimal · up to 84660

This change fixes a possible hang when a continuation calls get() on a run_loop-backed future. It also makes a throwing initial-value move in the async read-write mutex fail cleanly with the exception delivered to the receiver. Regression tests were added for both cases. No remaining merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names both primary changes: the run_loop future deadlock fix in make_future and the async_rw_mutex assertion fix. It is specific and matches the changeset, which modifies make_future.hpp and…
Description check Passed The description states the two problems, the affected files, and the fixes. It also lists the regression tests and the test results. It matches the changeset closely.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names both primary changes: the run_loop future deadlock fix in make_future and the async_rw_mutex assertion fix. It is specific and matches the changeset, which modifies make_future.hpp and async_rw_mutex.hpp and adds regression tests for both.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b20b6bc-1421-4c2f-b9f3-354ccc4e71ac
Commits

Reviewing files that changed from the base of the PR and between e717b47 and 8466080.

Files selected for processing: 4

  • libs/core/execution/include/hpx/execution/algorithms/make_future.hpp
  • libs/core/execution/include/hpx/synchronization/async_rw_mutex.hpp
  • libs/core/execution/tests/unit/algorithm_run_loop.cpp
  • libs/core/execution/tests/unit/async_rw_mutex_exception.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@hkaiser
hkaiser merged commit bf3a819 into master Nov 16, 2026
159 of 160 checks passed
@hkaiser
hkaiser deleted the fix-run-loop-future-get branch November 16, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: senders/receivers Implementations of the p0443r14 / p2300 + p1897 proposals type: defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant