Skip to content

Commit

Permalink
fix race in write timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Aug 27, 2024
1 parent ea5605b commit 8adb9a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func (ye *Error) Temporary() bool {
}

type GoAwayError struct {
Remote bool
ErrorCode uint32
Remote bool
}

func (e *GoAwayError) Error() string {
Expand Down
13 changes: 7 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,14 @@ func (s *Session) send() {
if err := s.sendLoop(); err != nil {
// Prefer the recvLoop error over the sendLoop error. The receive loop might have the error code
// received in a GoAway frame received just before the TCP RST that closed the sendLoop
//
// Take the shutdownLock to avoid closing the connection concurrently with a Close call.
s.shutdownLock.Lock()
s.conn.Close()
<-s.recvDoneCh
if _, ok := s.recvErr.(*GoAwayError); ok {
err = s.recvErr
if s.shutdownErr == nil {
s.conn.Close()
<-s.recvDoneCh
if _, ok := s.recvErr.(*GoAwayError); ok {
err = s.recvErr
}
s.shutdownErr = err
}
s.shutdownLock.Unlock()
s.close(err, false, 0)
Expand Down

0 comments on commit 8adb9a8

Please sign in to comment.