Browse Source
Merge pull request #464 from libp2p/fix/mock-race
fix a data-race in the mock net
pull/465/head
Steven Allen
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
5 additions and
0 deletions
-
p2p/net/mock/mock_stream.go
|
@ -56,6 +56,11 @@ func (s *stream) Write(p []byte) (n int, err error) { |
|
|
l := s.conn.link |
|
|
l := s.conn.link |
|
|
delay := l.GetLatency() + l.RateLimit(len(p)) |
|
|
delay := l.GetLatency() + l.RateLimit(len(p)) |
|
|
t := time.Now().Add(delay) |
|
|
t := time.Now().Add(delay) |
|
|
|
|
|
|
|
|
|
|
|
// Copy it.
|
|
|
|
|
|
cpy := make([]byte, len(p)) |
|
|
|
|
|
copy(cpy, p) |
|
|
|
|
|
|
|
|
select { |
|
|
select { |
|
|
case <-s.closed: // bail out if we're closing.
|
|
|
case <-s.closed: // bail out if we're closing.
|
|
|
return 0, s.writeErr |
|
|
return 0, s.writeErr |
|
|