Skip to content

Commit

Permalink
Merge pull request #464 from libp2p/fix/mock-race
Browse files Browse the repository at this point in the history
fix a data-race in the mock net
  • Loading branch information
Stebalien authored Oct 24, 2018
2 parents f046774 + 841a627 commit 1e38b9e
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 1e38b9e

Please sign in to comment.