Skip to content

Commit

Permalink
fix a data-race in the mock net
Browse files Browse the repository at this point in the history
This was causing ipfs/kubo#5637 (comment)
  • Loading branch information
Stebalien committed Oct 24, 2018
1 parent 30e4db2 commit 841a627
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions p2p/net/mock/mock_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (s *stream) Write(p []byte) (n int, err error) {
l := s.conn.link
delay := l.GetLatency() + l.RateLimit(len(p))
t := time.Now().Add(delay)

// Copy it.
cpy := make([]byte, len(p))
copy(cpy, p)

select {
case <-s.closed: // bail out if we're closing.
return 0, s.writeErr
Expand Down

0 comments on commit 841a627

Please sign in to comment.