Skip to content

[ISSUE #10860] Make DefaultPromise.get wait for completion - #10865

Open
yuluo-yx wants to merge 1 commit into
apache:developfrom
yuluo-yx:0808-yuluo/fix-17
Open

[ISSUE #10860] Make DefaultPromise.get wait for completion#10865
yuluo-yx wants to merge 1 commit into
apache:developfrom
yuluo-yx:0808-yuluo/fix-17

Conversation

@yuluo-yx

@yuluo-yx yuluo-yx commented Aug 8, 2026

Copy link
Copy Markdown
Member

Which Issue(s) This PR Fixes

Brief Description

The no-argument OpenMessaging DefaultPromise.get() now uses the existing wait path instead of returning a pending null result. The indefinite wait uses a state loop to handle spurious wakeups and restores the interrupt flag when interrupted.

Reading a completed value no longer notifies listeners again. Regression tests cover waiting for completion, failure propagation, and single listener notification.

How Did You Test This Change?

  • mise exec java@temurin-17.0.19+10 -- mvn -pl openmessaging -am -Dtest=DefaultPromiseTest -Dsurefire.failIfNoSpecifiedTests=false -Dspotbugs.skip=true test
  • Result: BUILD SUCCESS; 12 tests, 0 failures, 0 errors, 0 skipped.
  • Scope check: 2 files, 69 changed lines.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Fixes a critical correctness issue where DefaultPromise.get() returned immediately without waiting for the promise to complete. Also fixes spurious wakeup handling and interrupt flag restoration.

Analysis

  • Correctness ✅ — The old get() returning result directly (which is null before completion) defeats the entire purpose of a Promise. The fix to delegate to get(0) with proper wait semantics is correct. The while (isDoing()) loop handles spurious wakeups. The catch (InterruptedException) with Thread.currentThread().interrupt() properly restores the interrupt flag.
  • Tests ✅ — Three regression tests covering: basic wait-for-completion, timeout behavior, and the interrupted-flag restoration.
  • Compatibility ⚠️ — This is a behavioral change: callers of get() that relied on the old non-blocking behavior will now block. However, the old behavior was clearly a bug (a Promise that doesn't wait is useless), so this is the correct fix.

LGTM.


Automated review by github-manager-bot

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.29%. Comparing base (fd0c959) to head (4c97db8).

Files with missing lines Patch % Lines
...openmessaging/rocketmq/promise/DefaultPromise.java 50.00% 4 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10865      +/-   ##
=============================================
- Coverage      48.39%   48.29%   -0.10%     
+ Complexity     13562    13535      -27     
=============================================
  Files           1380     1380              
  Lines         101165   101167       +2     
  Branches       13127    13128       +1     
=============================================
- Hits           48962    48862     -100     
- Misses         46233    46318      +85     
- Partials        5970     5987      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OpenMessaging DefaultPromise.get returns before completion

3 participants