fix deadlock when sending stream data

This commit is contained in:
Marten Seemann 2018-12-18 16:10:17 +06:30
parent dadb6d395c
commit 8761cee0ef

View file

@ -96,10 +96,10 @@ func (s *sendStream) Write(p []byte) (int, error) {
}
s.dataForWriting = p
s.sender.onHasStreamData(s.streamID)
var bytesWritten int
var err error
var notifiedSender bool
for {
bytesWritten = len(p) - len(s.dataForWriting)
if !s.deadline.IsZero() && !time.Now().Before(s.deadline) {
@ -112,6 +112,10 @@ func (s *sendStream) Write(p []byte) (int, error) {
}
s.mutex.Unlock()
if !notifiedSender {
s.sender.onHasStreamData(s.streamID) // must be called without holding the mutex
notifiedSender = true
}
if s.deadline.IsZero() {
<-s.writeChan
} else {