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()).
| 787 | // this very Call (specified by |error_code|) rather than the error of the |
| 788 | // entire RPC (specified by c->FailedInline()). |
| 789 | void 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(); |
no test coverage detected