Don't close channel if it's already closed
This commit is contained in:
parent
72068efb4d
commit
6df8cf53c6
@ -106,6 +106,7 @@ func (c *Client) Call(rcvr, method string, arg interface{}, ret interface{}) err
|
||||
c.chs[chID] = make(chan *types.Response, 5)
|
||||
c.chMtx.Unlock()
|
||||
|
||||
channelClosed := false
|
||||
go func() {
|
||||
// Get type of channel elements
|
||||
chElemType := retVal.Type().Elem()
|
||||
@ -121,6 +122,8 @@ func (c *Client) Call(rcvr, method string, arg interface{}, ret interface{}) err
|
||||
// Close return channel
|
||||
retVal.Close()
|
||||
|
||||
channelClosed = true
|
||||
|
||||
break
|
||||
}
|
||||
// Get reflect value from channel response
|
||||
@ -148,12 +151,14 @@ func (c *Client) Call(rcvr, method string, arg interface{}, ret interface{}) err
|
||||
break
|
||||
}
|
||||
}
|
||||
if !channelClosed {
|
||||
c.Call("lrpc", "ChannelDone", id, nil)
|
||||
// Close and delete channel
|
||||
c.chMtx.Lock()
|
||||
close(c.chs[chID])
|
||||
delete(c.chs, chID)
|
||||
c.chMtx.Unlock()
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
// IF return value is not a pointer, return error
|
||||
|
Reference in New Issue
Block a user