forked from quic-go/quic-go
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user