From 8761cee0ef1c67a9d38010951c8ace0a612017c3 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 18 Dec 2018 16:10:17 +0630 Subject: [PATCH] fix deadlock when sending stream data --- send_stream.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/send_stream.go b/send_stream.go index f388cc6d..9e8f6954 100644 --- a/send_stream.go +++ b/send_stream.go @@ -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 {