diff --git a/conn/channel.go b/conn/channel.go index ae0621e1..8ea22341 100644 --- a/conn/channel.go +++ b/conn/channel.go @@ -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]