Commit f772aae9 authored by Steven Allen's avatar Steven Allen

don't hold the lock when closing

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/go-ipfs#2823
parent 709299bf
......@@ -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()
}
......@@ -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()
}
......
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