Lock the client when a non-parallel-safe function is called

Multiple Echo calls would overwrite themselfs. Lock the client to avoid this.
This commit is contained in:
sewi-cpan 2019-11-08 13:09:41 +01:00 committed by GitHub
parent d40cb7e2b9
commit 06a017e098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -323,6 +323,11 @@ func (client *Client) Echo(data []byte) (echo []byte, err error) {
}
var mutex sync.Mutex
mutex.Lock()
// Lock the client as only one echo may run parallel
client.Lock()
defer client.Unlock()
client.innerHandler.put("e", func(resp *Response) {
echo = resp.Data
mutex.Unlock()