From 9f2b528a60917e6446273926f4c676cac759d2b0 Mon Sep 17 00:00:00 2001 From: xtaci Date: Thu, 22 Sep 2016 18:26:45 +0800 Subject: [PATCH] fix a potential race in closing stream.die --- stream.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stream.go b/stream.go index f8b1c93..8c44dd8 100644 --- a/stream.go +++ b/stream.go @@ -111,7 +111,12 @@ func (s *Stream) Close() error { func (s *Stream) sessionClose() { s.dieLock.Lock() defer s.dieLock.Unlock() - close(s.die) + + select { + case <-s.die: + default: + close(s.die) + } } // pushBytes a slice into buffer