From 77d4573d9bd6305c9c8e3919367fd280f5343b70 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 29 Jul 2017 00:10:43 +0700 Subject: [PATCH] return an error when Write is called on a closed stream --- stream.go | 3 +++ stream_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/stream.go b/stream.go index 6a3d4a06f..45cf01a16 100644 --- a/stream.go +++ b/stream.go @@ -180,6 +180,9 @@ func (s *stream) Write(p []byte) (int, error) { if s.resetLocally.Get() || s.err != nil { return 0, s.err } + if s.finishedWriting.Get() { + return 0, fmt.Errorf("write on closed stream %d", s.streamID) + } if len(p) == 0 { return 0, nil } diff --git a/stream_test.go b/stream_test.go index 892530967..d14900b53 100644 --- a/stream_test.go +++ b/stream_test.go @@ -865,6 +865,12 @@ var _ = Describe("Stream", func() { Expect(str.finishedWriting.Get()).To(BeTrue()) }) + It("doesn't allow writes after it has been closed", func() { + str.Close() + _, err := strWithTimeout.Write([]byte("foobar")) + Expect(err).To(MatchError("write on closed stream 1337")) + }) + It("allows FIN", func() { str.Close() Expect(str.shouldSendFin()).To(BeTrue())