Skip to content

Commit

Permalink
fix message return before uuid write cause stuck (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: XingQiang Bai <[email protected]>
  • Loading branch information
dyy8888 and bxq2011hust authored Mar 6, 2023
1 parent 16bfa5b commit 25bb8da
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions conn/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,24 @@ func (hc *channelSession) doRPCRequest(ctx context.Context, msg interface{}) (io
return nil, err
}
msgBytes := rpcMsg.Encode()

response := &channelResponse{Message: nil, Notify: make(chan interface{})}
hc.mu.Lock()
hc.responses[rpcMsg.uuid] = response
hc.mu.Unlock()
if hc.c == nil {
hc.mu.Lock()
delete(hc.responses, rpcMsg.uuid)
hc.mu.Unlock()
return nil, errors.New("connection unavailable")
}
_, err = hc.c.Write(msgBytes)
if err != nil {
hc.mu.Lock()
delete(hc.responses, rpcMsg.uuid)
hc.mu.Unlock()
return nil, err
}
response := &channelResponse{Message: nil, Notify: make(chan interface{})}
hc.mu.Lock()
hc.responses[rpcMsg.uuid] = response
hc.mu.Unlock()
<-response.Notify
hc.mu.Lock()
response = hc.responses[rpcMsg.uuid]
Expand Down

0 comments on commit 25bb8da

Please sign in to comment.