From 4d6262328ec564152367fdc9952b3d395db26a59 Mon Sep 17 00:00:00 2001 From: Hlib Kanunnikov Date: Mon, 15 May 2023 12:53:31 +0200 Subject: [PATCH] fix: sendWindowUpdate respects deadlines (#105) --- session.go | 4 ++-- stream.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/session.go b/session.go index aecc20b..bc775f8 100644 --- a/session.go +++ b/session.go @@ -243,7 +243,7 @@ GET_ID: s.streamLock.Unlock() // Send the window update to create - if err := stream.sendWindowUpdate(); err != nil { + if err := stream.sendWindowUpdate(ctx.Done()); err != nil { defer span.Done() select { case <-s.synCh: @@ -271,7 +271,7 @@ func (s *Session) AcceptStream() (*Stream, error) { for { select { case stream := <-s.acceptCh: - if err := stream.sendWindowUpdate(); err != nil { + if err := stream.sendWindowUpdate(nil); err != nil { // don't return accept errors. s.logger.Printf("[WARN] error sending window update before accepting: %s", err) continue diff --git a/stream.go b/stream.go index 88d551e..e1e5602 100644 --- a/stream.go +++ b/stream.go @@ -120,7 +120,7 @@ START: n, _ = s.recvBuf.Read(b) // Send a window update potentially - err = s.sendWindowUpdate() + err = s.sendWindowUpdate(s.readDeadline.wait()) return n, err } @@ -209,7 +209,7 @@ func (s *Stream) sendFlags() uint16 { // sendWindowUpdate potentially sends a window update enabling // further writes to take place. Must be invoked with the lock. -func (s *Stream) sendWindowUpdate() error { +func (s *Stream) sendWindowUpdate(deadline <-chan struct{}) error { // Determine the flags if any flags := s.sendFlags() @@ -238,7 +238,7 @@ func (s *Stream) sendWindowUpdate() error { s.epochStart = now hdr := encode(typeWindowUpdate, flags, s.id, delta) - return s.session.sendMsg(hdr, nil, nil) + return s.session.sendMsg(hdr, nil, deadline) } // sendClose is used to send a FIN