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

Method OnComplete

src/brpc/controller.cpp:789–881  ·  view source on GitHub ↗

Note: A RPC call is probably consisted by several individual Calls such as retries and backup requests. This method simply cares about the error of this very Call (specified by |error_code|) rather than the error of the entire RPC (specified by c->FailedInline()).

Source from the content-addressed store, hash-verified

787// this very Call (specified by |error_code|) rather than the error of the
788// entire RPC (specified by c->FailedInline()).
789void Controller::Call::OnComplete(
790 Controller* c, int error_code/*note*/, bool responded, bool end_of_rpc) {
791 if (stream_user_data) {
792 stream_user_data->DestroyStreamUserData(sending_sock, c, error_code, end_of_rpc);
793 stream_user_data = NULL;
794 }
795
796 if (sending_sock != NULL) {
797 if (error_code != 0) {
798 sending_sock->AddRecentError();
799 }
800
801 if (enable_circuit_breaker) {
802 sending_sock->FeedbackCircuitBreaker(error_code,
803 butil::gettimeofday_us() - begin_time_us);
804 }
805 }
806
807 switch (c->connection_type()) {
808 case CONNECTION_TYPE_UNKNOWN:
809 break;
810 case CONNECTION_TYPE_SINGLE:
811 // Set main socket to be failed for connection refusal of streams.
812 // "single" streams are often maintained in a separate SocketMap and
813 // different from the main socket as well.
814 if (c->_stream_creator != NULL &&
815 does_error_affect_main_socket(error_code) &&
816 (sending_sock == NULL || sending_sock->id() != peer_id)) {
817 Socket::SetFailed(peer_id);
818 }
819 break;
820 case CONNECTION_TYPE_POOLED:
821 // NOTE: Not reuse pooled connection if this call fails and no response
822 // has been received through this connection
823 // Otherwise in-flight responses may come back in future and break the
824 // assumption that one pooled connection cannot have more than one
825 // message at the same time.
826 if (sending_sock != NULL && (error_code == 0 || responded)) {
827 if (!sending_sock->is_read_progressive()) {
828 // Normally-read socket which will not be used after RPC ends,
829 // safe to return. Notice that Socket::is_read_progressive may
830 // differ from Controller::is_response_read_progressively()
831 // because RPC possibly ends before setting up the socket.
832 sending_sock->ReturnToPool();
833 } else {
834 // Progressively-read socket. Should be returned when the read
835 // ends. The method handles the details.
836 sending_sock->OnProgressiveReadCompleted();
837 }
838 break;
839 }
840 // fall through
841 case CONNECTION_TYPE_SHORT:
842 if (sending_sock != NULL) {
843 // Check the comment in CONNECTION_TYPE_POOLED branch.
844 if (!sending_sock->is_read_progressive()) {
845 if (c->_stream_creator == NULL) {
846 sending_sock->SetFailed();

Callers 2

EndRPCMethod · 0.45

Calls 13

AddRecentErrorMethod · 0.80
connection_typeMethod · 0.80
ReturnToPoolMethod · 0.80
SetLogOffMethod · 0.80
gettimeofday_usFunction · 0.50
DestroyStreamUserDataMethod · 0.45
idMethod · 0.45
SetFailedMethod · 0.45
FeedbackMethod · 0.45

Tested by

no test coverage detected