MCPcopy Create free account
hub / github.com/apache/brpc / EndRPC

Method EndRPC

src/brpc/controller.cpp:883–1003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881}
882
883void Controller::EndRPC(const CompletionInfo& info) {
884 if (_timeout_id != 0) {
885 bthread_timer_del(_timeout_id);
886 _timeout_id = 0;
887 }
888
889 // End _current_call and _unfinished_call.
890 if (info.id == current_id() || info.id == _correlation_id) {
891 if (_current_call.sending_sock != NULL) {
892 _remote_side = _current_call.sending_sock->remote_side();
893 _local_side = _current_call.sending_sock->local_side();
894 }
895
896 if (_unfinished_call != NULL) {
897 // When _current_call is successful, mark _unfinished_call as
898 // EBACKUPREQUEST, we can't use 0 because the server possibly
899 // never respond, we can't use ERPCTIMEDOUT because _current_call
900 // is sent after _unfinished_call which is not necessarily timedout
901 // When _current_call is error, mark _unfinished_call with the
902 // same error. This is not accurate as well, but we have to end
903 // _unfinished_call with some sort of error anyway.
904 const int err = (_error_code == 0 ? EBACKUPREQUEST : _error_code);
905 _unfinished_call->OnComplete(this, err, false, false);
906 delete _unfinished_call;
907 _unfinished_call = NULL;
908 }
909 // TODO: Replace this with stream_creator.
910 HandleStreamConnection(_current_call.sending_sock.get());
911 _current_call.OnComplete(this, _error_code, info.responded, true);
912 } else {
913 // Even if _unfinished_call succeeded, we don't use EBACKUPREQUEST
914 // (which gets punished in LALB) for _current_call because _current_call
915 // is sent after _unfinished_call, it's just normal that _current_call
916 // does not respond before _unfinished_call.
917 if (_unfinished_call == NULL) {
918 CHECK(false) << "A previous non-backup request responded, cid="
919 << info.id << " current_cid=" << current_id()
920 << " initial_cid=" << _correlation_id
921 << " stream_user_data=" << _current_call.stream_user_data
922 << " sending_sock=" << _current_call.sending_sock.get();
923 }
924 _current_call.OnComplete(this, ECANCELED, false, false);
925 if (_unfinished_call != NULL) {
926 if (_unfinished_call->sending_sock != NULL) {
927 _remote_side = _unfinished_call->sending_sock->remote_side();
928 _local_side = _unfinished_call->sending_sock->local_side();
929 }
930 // TODO: Replace this with stream_creator.
931 HandleStreamConnection(_unfinished_call->sending_sock.get());
932 if (get_id(_unfinished_call->nretry) == info.id) {
933 _unfinished_call->OnComplete(
934 this, _error_code, info.responded, true);
935 } else {
936 CHECK(false) << "A previous non-backup request responded";
937 _unfinished_call->OnComplete(this, ECANCELED, false, true);
938 }
939
940 delete _unfinished_call;

Callers 1

RunEndRPCMethod · 0.80

Calls 15

bthread_timer_delFunction · 0.85
DoNothingFunction · 0.85
bthread_about_to_quitFunction · 0.85
RunUserCodeFunction · 0.85
set_ending_cidMethod · 0.80
set_asyncMethod · 0.80
gettimeofday_usFunction · 0.50
remote_sideMethod · 0.45
local_sideMethod · 0.45
OnCompleteMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected