Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/never discard the callback task #413

Merged
merged 2 commits into from
Apr 1, 2020
Merged

Conversation

fengjiachun
Copy link
Contributor

Motivation:

The bolt default callback task rejection policy is discard policy, we should ensure that never discard the callback task.

    /**
     * @see com.alipay.remoting.InvokeCallbackListener#onResponse(com.alipay.remoting.InvokeFuture)
     */
    @Override
    public void onResponse(InvokeFuture future) {
        InvokeCallback callback = future.getInvokeCallback();
        if (callback != null) {
            CallbackTask task = new CallbackTask(this.getRemoteAddress(), future);
            if (callback.getExecutor() != null) {
                // There is no need to switch classloader, because executor is provided by user.
                try {
                    callback.getExecutor().execute(task);
                } catch (RejectedExecutionException e) {
                    if (callback instanceof RejectionProcessableInvokeCallback) {
                        switch (((RejectionProcessableInvokeCallback) callback)
                            .rejectedExecutionPolicy()) {
                            case CALLER_RUNS:
                                task.run();
                                break;
                            case CALLER_HANDLE_EXCEPTION:
                                callback.onException(e);
                                break;
                            case DISCARD:
                            default:
                                logger.warn("Callback thread pool busy. discard the callback");
                                break;
                        }
                    } else {
                        logger.warn("Callback thread pool busy.");
                    }
                }
            } else {
                task.run();
            }
        }
    }

Modification:

Impl RejectionProcessableInvokeCallback

Result:

If there is no issue then describe the changes introduced by this PR.

@killme2008
Copy link
Contributor

这有点坑了,得改下

@killme2008
Copy link
Contributor

CALLER_HANDLE_EXCEPTION 策略是不是更好, calle run 会阻塞当前发送线程,宁愿 callback 里去处理异常

@sofastack-bot sofastack-bot bot added size/M and removed size/XS labels Apr 1, 2020
@fengjiachun
Copy link
Contributor Author

CALLER_HANDLE_EXCEPTION 策略是不是更好, calle run 会阻塞当前发送线程,宁愿 callback 里去处理异常

默认选项改为 CALLER_HANDLE_EXCEPTION 并且配置化了

@SteNicholas SteNicholas merged commit 0c592b5 into master Apr 1, 2020
@killme2008 killme2008 deleted the feat/improve_callback branch April 1, 2020 13:11
@fengjiachun fengjiachun mentioned this pull request Apr 17, 2020
12 tasks
zongtanghu pushed a commit that referenced this pull request Apr 28, 2020
* insure never discard the callback task

* configurable for rejected_execution_policy, and caller_handle_exception as default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants