From 599d93796636ff2256396682c7d99726e9f6f9eb Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 25 Mar 2020 16:48:32 +0700 Subject: [PATCH] make Stream.Close() a no-op after the stream was closed for shutdown --- send_stream.go | 6 +++++- send_stream_test.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/send_stream.go b/send_stream.go index 59457042..df1b753b 100644 --- a/send_stream.go +++ b/send_stream.go @@ -311,9 +311,13 @@ func (s *sendStream) queueRetransmission(f wire.Frame) { func (s *sendStream) Close() error { s.mutex.Lock() + if s.closedForShutdown { + s.mutex.Unlock() + return nil + } if s.canceledWrite { s.mutex.Unlock() - return fmt.Errorf("Close called for canceled stream %d", s.streamID) + return fmt.Errorf("close called for canceled stream %d", s.streamID) } s.ctxCancel() s.finishedWriting = true diff --git a/send_stream_test.go b/send_stream_test.go index 911d4aca..3bb4421e 100644 --- a/send_stream_test.go +++ b/send_stream_test.go @@ -438,6 +438,11 @@ var _ = Describe("Send Stream", func() { f, hasMoreData := str.popStreamFrame(1000) Expect(f).To(BeNil()) Expect(hasMoreData).To(BeFalse()) + + Expect(str.Close()).To(Succeed()) + f, hasMoreData = str.popStreamFrame(1000) + Expect(f).To(BeNil()) + Expect(hasMoreData).To(BeFalse()) }) It("doesn't allow FIN twice", func() {