gracefully handle concurrent stream writes and cancellations

If the complete slice passed to Stream.Write() is sent out, and the
stream is canceled concurrently (either by calling Stream.CancelWrite()
or by receiving a STOP_SENDING frame), we don't need to return an error
for the Write() call.
This commit is contained in:
Marten Seemann
2020-06-23 13:07:28 +07:00
parent 3289d2ce38
commit 4ff3af3305
2 changed files with 29 additions and 0 deletions

View File

@@ -173,6 +173,9 @@ func (s *sendStream) Write(p []byte) (int, error) {
s.mutex.Lock()
}
if bytesWritten == len(p) {
return bytesWritten, nil
}
if s.closeForShutdownErr != nil {
return bytesWritten, s.closeForShutdownErr
} else if s.cancelWriteErr != nil {