From 3e6224d8e9782e877311e335c32450b8447827e7 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 13 Apr 2020 16:38:46 +0100 Subject: [PATCH] Protect buffer closing --- internal/multiplex/streamBuffer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/multiplex/streamBuffer.go b/internal/multiplex/streamBuffer.go index d171b36..1004cc5 100644 --- a/internal/multiplex/streamBuffer.go +++ b/internal/multiplex/streamBuffer.go @@ -65,7 +65,6 @@ func (sb *streamBuffer) Write(f Frame) (toBeClosed bool, err error) { // when there'fs no ooo packages in heap and we receive the next package in order if len(sb.sh) == 0 && f.Seq == sb.nextRecvSeq { if f.Closing != C_NOOP { - sb.buf.Close() return true, nil } else { sb.buf.Write(f.Payload) @@ -83,7 +82,6 @@ func (sb *streamBuffer) Write(f Frame) (toBeClosed bool, err error) { for len(sb.sh) > 0 && sb.sh[0].Seq == sb.nextRecvSeq { f = *heap.Pop(&sb.sh).(*Frame) if f.Closing != C_NOOP { - sb.buf.Close() return true, nil } else { sb.buf.Write(f.Payload) @@ -102,6 +100,9 @@ func (sb *streamBuffer) WriteTo(w io.Writer) (int64, error) { } func (sb *streamBuffer) Close() error { + sb.recvM.Lock() + defer sb.recvM.Unlock() + return sb.buf.Close() }