cmd/faucet: make a locked copy of f.reqs

This commit is contained in:
BurtonQin 2020-02-14 17:22:07 +08:00
parent 80f692f123
commit bad4dc2c99

View file

@ -361,17 +361,17 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) {
}
// Send over the initial stats and the latest header
f.lock.RLock()
reqs := f.reqs
f.lock.RUnlock()
if err = send(conn, map[string]interface{}{
"funds": new(big.Int).Div(balance, ether),
"funded": nonce,
"peers": f.stack.Server().PeerCount(),
"requests": f.reqs,
"requests": 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