Skip to content

invoke onError when timeout occurred in async mode #5827

@haiyang1985

Description

@haiyang1985
  • 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: MacOs
  • Java version: 1.8

Steps to reproduce this issue

1.start DemoService provider

2.Set onreturn and onthrow for sayHello method in async mode, and then start consumer.

<bean id="demoCallback" class="com.alibaba.dubbo.samples.notify.impl.NotifyImpl" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.DemoService">
    <dubbo:method name="sayHello" onreturn="demoCallback.onreturn" onthrow="demoCallback.onthrow"/>
</dubbo:reference>
  1. send a request in async mode.
    When timeout occurred, demoCallback.onthrow callback have not been invoked.

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

Expected Result

onthrow callback should be invoked.

Actual Result

onthrow have not be invoked.

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

Once exception occurs, CallbackRegistrationInvoker onError will be invoked

@Override
public Result invoke(Invocation invocation) throws RpcException {
    Result asyncResult = filterInvoker.invoke(invocation);

    asyncResult = asyncResult.whenCompleteWithContext((r, t) -> {
        for (int i = filters.size() - 1; i >= 0; i--) {
            Filter filter = filters.get(i);
            // onResponse callback
            if (filter instanceof ListenableFilter) {
                Filter.Listener listener = ((ListenableFilter) filter).listener();
                if (listener != null) {
                    if (t == null) {
                        listener.onResponse(r, filterInvoker, invocation);
                    } else {
                        listener.onError(t, filterInvoker, invocation);
                    }
                }
            } else {
                filter.onResponse(r, filterInvoker, invocation);
            }
        }
    });
    return asyncResult;
}

But, the FutureListener's onError is not implemented, cannot invoke the onreturn/onerror callback.

class FutureListener implements Listener {
    @Override
    public void onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
        if (result.hasException()) {
            fireThrowCallback(invoker, invocation, result.getException());
        } else {
            fireReturnCallback(invoker, invocation, result.getValue());
        }
    }

    @Override
    public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {

    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions