don’t return data for writing from a stream if it was closed with an error

This commit is contained in:
Marten Seemann
2017-01-03 15:31:32 +07:00
parent bf0caf3c03
commit 9e09198df6
2 changed files with 21 additions and 2 deletions

View File

@@ -158,13 +158,20 @@ func (s *stream) Write(p []byte) (int, error) {
func (s *stream) lenOfDataForWriting() protocol.ByteCount {
s.mutex.Lock()
l := protocol.ByteCount(len(s.dataForWriting))
var l protocol.ByteCount
if s.err == nil {
l = protocol.ByteCount(len(s.dataForWriting))
}
s.mutex.Unlock()
return l
}
func (s *stream) getDataForWriting(maxBytes protocol.ByteCount) []byte {
s.mutex.Lock()
if s.err != nil {
s.mutex.Unlock()
return nil
}
if s.dataForWriting == nil {
s.mutex.Unlock()
return nil
@@ -207,7 +214,6 @@ func (s *stream) sentFin() {
func (s *stream) AddStreamFrame(frame *frames.StreamFrame) error {
maxOffset := frame.Offset + frame.DataLen()
err := s.flowControlManager.UpdateHighestReceived(s.streamID, maxOffset)
if err != nil {
return err
}