]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Fix race in stats
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 20 May 2018 01:26:46 +0000 (03:26 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 20 May 2018 01:26:46 +0000 (03:26 +0200)
uapi.go

diff --git a/uapi.go b/uapi.go
index fa60709d623bc5873a7351da0b90bf0d7e196e8d..4f40fa6e2db28cab1872d52a2e6d856f525a209a 100644 (file)
--- 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) {