Merge pull request #773 from lucas-clemente/fix-772

return an error when Write is called on a closed stream
This commit is contained in:
Marten Seemann
2017-07-29 07:10:52 +07:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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())