710d6a9 CLIENT: Retry request after EPIPE

Authored and Committed by lslebodn 8 years ago
    CLIENT: Retry request after EPIPE
    
    We have a function sss_cli_check_socket which checks
    socket in client code. The socket is reopened in case of some
    issues e.g. responder terminated connections ...
    
    We use syscall poll for checking status of socket.
    It's not 100% reliable method because there is still
    chance that responder will terminate socket after this check.
    
    Here is a schema of sss_*_make_request functions:
        sss_cli_check_socket
        sss_cli_make_request_nochecks {
           sss_cli_send_req {
               poll
               send
           }
           sss_cli_recv_rep {
               poll
               read
           }
        }
    
    The syscall pool does not return EPIPE directly but we convert
    special revents from poll to EPIPE. As it was mentioned earlier,
    checking of socket in the sss_cli_check_socket is not 100% reliable.
    It can happen very rarely due to TOCTOU issue (Time of check to time of use)
    
    We can return EPIPE from the sss_cli_make_request_nochecks function
    in case of failure in poll in sss_cli_send_req. The send function
    in sss_cli_send_req can also return EPIPE is responder close socket
    in the same time. The send function can succeed in sss_cli_send_req
    but it does not mean that responder read the message. It can happen
    that timer for closing socket can be handled before reading a message.
    Therefore there is a still a chance that we might return EPIPE in case
    of failure in poll in sss_cli_recv_rep.
    
    Therefore we need to reconnect to responder(sss_cli_check_socket)
    in case of EPIPE returned from sss_cli_make_request_nochecks and
    try to do the same request one more time.
    
    Resolves:
    https://fedorahosted.org/sssd/ticket/2626
    
    Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
    (cherry picked from commit 6748a4c9d75db997c724c1dcea541e0047742f52)
    
        
file modified
+48 -0