Skip to content

[ISSUE #10747] Fix InvokeCallback completion order - #10753

Open
ai-yang wants to merge 1 commit into
apache:developfrom
ai-yang:agent/fix-invokecallback-order
Open

[ISSUE #10747] Fix InvokeCallback completion order#10753
ai-yang wants to merge 1 commit into
apache:developfrom
ai-yang:agent/fix-invokecallback-order

Conversation

@ai-yang

@ai-yang ai-yang commented Aug 2, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Brief Description

invokeAsyncImpl() chained whenComplete, thenAccept, and exceptionally. This caused operationComplete to run before operationSucceed or operationFail, contrary to the InvokeCallback contract, and allowed exceptions thrown by callback methods to flow into the invocation-failure stage.

The fix handles the original invocation result in one terminal whenComplete callback:

  • invoke operationSucceed or operationFail before operationComplete;
  • preserve unwrapping of the original remoting failure;
  • keep callback failures separate from the remoting invocation outcome;
  • invoke final completion from finally, including when the outcome callback throws.

Callback exceptions are caught and logged locally because invokeAsyncImpl() returns void and does not expose the dependent completion stage. This guarantees that operationComplete still runs and prevents callback failures from being misclassified as remoting invocation failures.

How Did You Test This Change?

  • Unmodified develop: the deterministic callback-order regression failed in 5/5 isolated JDK 8 Maven processes.
  • Affected callback regressions: 20 isolated Maven/JVM processes at 5/5 each (100/100 total).
  • Complete client reactor: common 241/241, remoting 177/177, and client 578 tests with 1 skip, 0 failures, and 0 errors.
  • Checkstyle: 0 violations.
  • SpotBugs: 0 bug instances and 0 errors.
  • Maven validate: passed.
  • git diff --check: passed.

Signed-off-by: Rui <1685901819@qq.com>
@ai-yang
ai-yang marked this pull request as ready for review August 2, 2026 14:22

@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.

Review by github-manager-bot

Summary

Restructures invokeAsyncImpl to guarantee that outcome callbacks (operationSucceed/operationFail) are always invoked before the completion callback (operationComplete), and wraps both in try-catch to prevent one failure from blocking the other.

Findings

  • [Info] NettyRemotingAbstract.java:680-707 — The single whenComplete handler replaces the previous thenAccept/exceptionally chain, eliminating the ordering ambiguity. Outcome callback is now explicitly called first, then completion callback.
  • [Info] The try-catch around each callback invocation ensures that a misbehaving callback cannot prevent the other from executing. This is important for cleanup paths.
  • [Info] NettyRemotingClientTest.java — Tests now verify callback ordering with InOrder and cover the case where a callback throws. The new testInvokeAsyncCompleteFailureDoesNotInvokeFailureCallback test validates that operationFail receives the correct exception instance.

Suggestions

  • Consider adding a brief comment in the whenComplete handler explaining why outcome must precede completion (contract: callers may depend on outcome state in operationComplete).

Automated review by github-manager-bot

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] invokeAsyncImpl violates InvokeCallback completion order

2 participants