Skip to content

Commit

Permalink
don't hold the lock when closing
Browse files Browse the repository at this point in the history
In libp2p, Close is assumed to be threadsafe and we'd like to interrupt
in-progress reads/writes.

As a matter of fact, we're lucky this hasn't caused close to hang. If we had
tried to close the reader before closing the writer, we would have blocked on a
concurrent read call.

Part of ipfs/kubo#2823
  • Loading branch information
Stebalien committed Dec 11, 2017
1 parent 709299b commit f772aae
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions msgio.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ func (s *writer) WriteMsg(msg []byte) (err error) {
}

func (s *writer) Close() error {
s.lock.Lock()
defer s.lock.Unlock()

if c, ok := s.W.(io.Closer); ok {
return c.Close()
}
Expand Down Expand Up @@ -216,9 +213,6 @@ func (s *reader) ReleaseMsg(msg []byte) {
}

func (s *reader) Close() error {
s.lock.Lock()
defer s.lock.Unlock()

if c, ok := s.R.(io.Closer); ok {
return c.Close()
}
Expand Down

0 comments on commit f772aae

Please sign in to comment.