Commit e6a2a408 authored by Steven Allen's avatar Steven Allen

bitswap: fix stat data race

parent 13f4ed3c
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"context" "context"
"errors" "errors"
"sync" "sync"
"sync/atomic"
"time" "time"
bssrs "github.com/ipfs/go-bitswap/sessionrequestsplitter" bssrs "github.com/ipfs/go-bitswap/sessionrequestsplitter"
...@@ -292,7 +291,9 @@ func (bs *Bitswap) receiveBlockFrom(blk blocks.Block, from peer.ID) error { ...@@ -292,7 +291,9 @@ func (bs *Bitswap) receiveBlockFrom(blk blocks.Block, from peer.ID) error {
} }
func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg.BitSwapMessage) { func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg.BitSwapMessage) {
atomic.AddUint64(&bs.counters.messagesRecvd, 1) bs.counterLk.Lock()
bs.counters.messagesRecvd++
bs.counterLk.Unlock()
// This call records changes to wantlists, blocks received, // This call records changes to wantlists, blocks received,
// and number of bytes transfered. // and number of bytes transfered.
......
...@@ -104,7 +104,11 @@ func TestSessionBetweenPeers(t *testing.T) { ...@@ -104,7 +104,11 @@ func TestSessionBetweenPeers(t *testing.T) {
} }
} }
for _, is := range inst[2:] { for _, is := range inst[2:] {
if is.Exchange.counters.messagesRecvd > 2 { stat, err := is.Exchange.Stat()
if err != nil {
t.Fatal(err)
}
if stat.MessagesReceived > 2 {
t.Fatal("uninvolved nodes should only receive two messages", is.Exchange.counters.messagesRecvd) t.Fatal("uninvolved nodes should only receive two messages", is.Exchange.counters.messagesRecvd)
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment