Skip to content

Commit

Permalink
fix: sendWindowUpdate respects deadlines (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored May 15, 2023
1 parent 1c09f2a commit 4d62623
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d62623

Please sign in to comment.