From 8da43508f8405ea77db51ece2615f5f9338002b6 Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 17 Jul 2019 09:49:01 +0200 Subject: [PATCH] abci/client: fix DATA RACE in gRPC client (#3798) * Remove go func {}() closes #357 - Remove go func(){}() that caused race condiditon - To reproduce - add -race in make file to `install_abci` - Remove `CGO_ENABLED=0` & add -race to `install` Signed-off-by: Marko Baricevic * remove -race * fix data race also, reorder callbacks similarly to socket client --- abci/client/grpc_client.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go index 23d790550..8c444abc5 100644 --- a/abci/client/grpc_client.go +++ b/abci/client/grpc_client.go @@ -228,18 +228,22 @@ func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response) reqres.Done() // Release waiters reqres.SetDone() // so reqRes.SetCallback will run the callback - // go routine for callbacks + // goroutine for callbacks go func() { - // Notify reqRes listener if set - if cb := reqres.GetCallback(); cb != nil { - cb(res) - } + cli.mtx.Lock() + defer cli.mtx.Unlock() // Notify client listener if set if cli.resCb != nil { cli.resCb(reqres.Request, res) } + + // Notify reqRes listener if set + if cb := reqres.GetCallback(); cb != nil { + cb(res) + } }() + return reqres }