• N
    rpc: client: stream: fix multi thread abort/finish · d63c82df
    Nikolay Shirokovskiy 提交于
    If 2 threads call abort for example then one of them
    will hang because client will send 2 abort messages and
    server will reply only on first of them, the second will be
    ignored. And on server reply client changes the state only
    one of abort message to complete, the second will hang forever.
    There are other similar issues.
    
    We should complete all messages waiting reply if we got
    error or expected abort/finish reply from server. Also if one
    thread send finish and another abort one of them will win
    the race and server will either abort or finish stream. If
    stream is aborted then thread requested finishing should report
    error. In order to archive this let's keep stream closing reason
    in @closed field. If we receive VIR_NET_OK message for stream
    then stream is finished if oldest (closest to queue end) message
    in stream queue is finish message and stream is aborted if oldest
    message is abort message. Otherwise it is protocol error.
    
    By the way we need to fix case of receiving VIR_NET_CONTINUE
    message. Now we take oldest message in queue and check if
    this is dummy message. If one thread first sends abort and
    second thread then receives data then oldest message is abort
    message and second thread won't be notified when data arrives.
    Let's find oldest dummy message instead.
    Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
    Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
    d63c82df
virnetclientstream.h 3.7 KB