From 06a017e098c83c420585a3079b14089f82c1ff80 Mon Sep 17 00:00:00 2001 From: sewi-cpan Date: Fri, 8 Nov 2019 13:09:41 +0100 Subject: [PATCH] Lock the client when a non-parallel-safe function is called Multiple Echo calls would overwrite themselfs. Lock the client to avoid this. --- client/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/client.go b/client/client.go index bf95cf4..21c70d0 100644 --- a/client/client.go +++ b/client/client.go @@ -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()