Skip to content

RpcContext.getContext().asyncCall return a new not completed CompletableFuture when throw RpcException #5606

@mr3

Description

@mr3
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.3
  • Operating System version: Windows 10
  • Java version: 1.8

Steps to reproduce this issue

  1. Here is my execution code
CompletableFuture<xxxxResponse> rpcFuture = RpcContext.getContext().asyncCall(() -> invokeRpc());

rpcFuture.whenComplete((rpcResult, throwable) -> {
    xxx;
});
  1. When asyncCall throw RpcException, it will return a instance of CompletableFuture, but not completed, and so the code of the following process cannot be executed, it is blocked

    RpcContext asyncCall return new CompletableFuture code

/**
     * Async invocation. Timeout will be handled even if <code>Future.get()</code> is not called.
     *
     * @param callable
     * @return get the return result from <code>future.get()</code>
     */
    @SuppressWarnings("unchecked")
    public <T> CompletableFuture<T> asyncCall(Callable<T> callable) {
        try {
            hide code snippet....
        } catch (final RpcException e) {
            return new CompletableFuture<T>() {
                @Override
                public boolean cancel(boolean mayInterruptIfRunning) {
                    return false;
                }

                @Override
                public boolean isCancelled() {
                    return false;
                }

                @Override
                public boolean isDone() {
                    return true;
                }

                @Override
                public T get() throws InterruptedException, ExecutionException {
                    throw new ExecutionException(e.getCause());
                }

                @Override
                public T get(long timeout, TimeUnit unit)
                        throws InterruptedException, ExecutionException,
                        TimeoutException {
                    return get();
                }
            };
        }
        return ((CompletableFuture<T>) getContext().getFuture());
    }

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

Return a completed completableFuture instance, so the code of the following process can be executed.

Actual Result

return a not completed completableFuture instance.

If there is an exception, please attach the exception trace:

Just put your stack trace here!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions