From df4cdf2294ec146e4577fc013816b420e0afa572 Mon Sep 17 00:00:00 2001 From: Who Soup Date: Wed, 16 Oct 2019 11:58:16 +0200 Subject: [PATCH] make counter atomic to stop race conditions --- jsonrpc.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jsonrpc.go b/jsonrpc.go index d38009c..4ac9cda 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -13,6 +13,7 @@ import ( "io/ioutil" "net/http" "strings" + "sync/atomic" "time" ) @@ -353,11 +354,10 @@ func walletRequest(req *JSON2Request) (*JSON2Response, error) { } // newCounter is used to generate the ID field for the JSON2Request -func newCounter() func() int { - count := 0 - return func() int { - count += 1 - return count +func newCounter() func() uint32 { + var count uint32 + return func() uint32 { + return atomic.AddUint32(&count, 1) } }