From e31aef303020165f73d82a116c10e49cd417ed11 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Sat, 29 Dec 2018 00:02:59 +0000 Subject: [PATCH] Stop repetitive closing --- internal/multiplex/stream.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/multiplex/stream.go b/internal/multiplex/stream.go index b23ac27..84ef6dc 100644 --- a/internal/multiplex/stream.go +++ b/internal/multiplex/stream.go @@ -120,6 +120,12 @@ func (stream *Stream) passiveClose() { func (stream *Stream) Close() error { stream.writingM.Lock() + select { + case <-stream.die: + stream.writingM.Unlock() + return errors.New("Already Closed") + default: + } stream.heliumMask.Do(func() { close(stream.die) }) // Notify remote that this stream is closed