change conn.closed flag by hold the lock

master
fangdingjun 6 years ago
parent ac31db180c
commit 8288f2a989

@ -344,10 +344,16 @@ func (c *Conn) serve(s *stream) {
// Close close the connection // Close close the connection
func (c *Conn) Close() error { func (c *Conn) Close() error {
c.lock.Lock()
if c.closed { if c.closed {
c.lock.Unlock()
return nil return nil
} }
c.closed = true c.closed = true
c.lock.Unlock()
// stream.Close may require the conn.Lock
// so must not hold the lock here
for _, s := range c.streams { for _, s := range c.streams {
s.Close() s.Close()
} }

Loading…
Cancel
Save