diff --git a/client/client.go b/client/client.go index b4be8e9..77d5e2e 100644 --- a/client/client.go +++ b/client/client.go @@ -299,6 +299,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() diff --git a/client/pool.go b/client/pool.go index 6a205cd..1044825 100644 --- a/client/pool.go +++ b/client/pool.go @@ -94,8 +94,6 @@ func (pool *Pool) Remove(addr string) { func (pool *Pool) Do(funcname string, data []byte, flag byte, h ResponseHandler) (addr, handle string, err error) { client := pool.selectServer() - client.Lock() - defer client.Unlock() handle, err = client.Do(funcname, data, flag, h) addr = client.addr return @@ -104,8 +102,6 @@ func (pool *Pool) Do(funcname string, data []byte, func (pool *Pool) DoBg(funcname string, data []byte, flag byte) (addr, handle string, err error) { client := pool.selectServer() - client.Lock() - defer client.Unlock() handle, err = client.DoBg(funcname, data, flag) addr = client.addr return @@ -115,8 +111,6 @@ func (pool *Pool) DoBg(funcname string, data []byte, // !!!Not fully tested.!!! func (pool *Pool) Status(addr, handle string) (status *Status, err error) { if client, ok := pool.Clients[addr]; ok { - client.Lock() - defer client.Unlock() status, err = client.Status(handle) } else { err = ErrNotFound @@ -136,8 +130,6 @@ func (pool *Pool) Echo(addr string, data []byte) (echo []byte, err error) { return } } - client.Lock() - defer client.Unlock() echo, err = client.Echo(data) return }