From: Jason A. Donenfeld Date: Sun, 20 May 2018 01:26:46 +0000 (+0200) Subject: Fix race in stats X-Git-Tag: 0.0.20180524~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a68c1ab175f8b45cb478e2a05732e1179efa0fb;p=thirdparty%2Fwireguard-go.git Fix race in stats --- diff --git a/uapi.go b/uapi.go index fa60709..4f40fa6 100644 --- a/uapi.go +++ b/uapi.go @@ -85,8 +85,8 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError { send(fmt.Sprintf("last_handshake_time_sec=%d", secs)) send(fmt.Sprintf("last_handshake_time_nsec=%d", nano)) - send(fmt.Sprintf("tx_bytes=%d", peer.stats.txBytes)) - send(fmt.Sprintf("rx_bytes=%d", peer.stats.rxBytes)) + send(fmt.Sprintf("tx_bytes=%d", atomic.LoadUint64(&peer.stats.txBytes))) + send(fmt.Sprintf("rx_bytes=%d", atomic.LoadUint64(&peer.stats.rxBytes))) send(fmt.Sprintf("persistent_keepalive_interval=%d", peer.persistentKeepaliveInterval)) for _, ip := range device.allowedips.EntriesForPeer(peer) {