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