From 80f692f12391fc3d7a4d73858f4da106faca5548 Mon Sep 17 00:00:00 2001 From: BurtonQin Date: Thu, 13 Feb 2020 23:25:38 +0800 Subject: [PATCH] cmd/faucet: add Rlock to protect f.reqs in apiHandler --- cmd/faucet/faucet.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index 77938efabd..09968f8e38 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -360,6 +360,7 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) { } } // Send over the initial stats and the latest header + f.lock.RLock() if err = send(conn, map[string]interface{}{ "funds": new(big.Int).Div(balance, ether), "funded": nonce, @@ -367,8 +368,10 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) { "requests": f.reqs, }, 3*time.Second); err != nil { log.Warn("Failed to send initial stats to client", "err", err) + f.lock.RUnlock() return } + f.lock.RUnlock() if err = send(conn, head, 3*time.Second); err != nil { log.Warn("Failed to send initial header to client", "err", err) return