Skip to content

Commit 37531b1

Browse files
authored
cmd/faucet: protect f.reqs with Rlock to prevent data race (#20669)
* cmd/faucet: add Rlock to protect f.reqs in apiHandler * cmd/faucet: make a locked copy of f.reqs
1 parent 8556905 commit 37531b1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cmd/faucet/faucet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,14 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) {
360360
}
361361
}
362362
// Send over the initial stats and the latest header
363+
f.lock.RLock()
364+
reqs := f.reqs
365+
f.lock.RUnlock()
363366
if err = send(conn, map[string]interface{}{
364367
"funds": new(big.Int).Div(balance, ether),
365368
"funded": nonce,
366369
"peers": f.stack.Server().PeerCount(),
367-
"requests": f.reqs,
370+
"requests": reqs,
368371
}, 3*time.Second); err != nil {
369372
log.Warn("Failed to send initial stats to client", "err", err)
370373
return

0 commit comments

Comments
 (0)