From 8288f2a989205fdb8c2f0194b19bb58a602cb6b8 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Sun, 29 Jul 2018 14:16:13 +0800 Subject: [PATCH] change conn.closed flag by hold the lock --- conn.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conn.go b/conn.go index 22c5fec..1c2f012 100644 --- a/conn.go +++ b/conn.go @@ -344,10 +344,16 @@ func (c *Conn) serve(s *stream) { // Close close the connection func (c *Conn) Close() error { + c.lock.Lock() if c.closed { + c.lock.Unlock() return nil } 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 { s.Close() }