Skip to content

Commit 8adb9a8

Browse files
committed
fix race in write timeout
1 parent ea5605b commit 8adb9a8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func (ye *Error) Temporary() bool {
2424
}
2525

2626
type GoAwayError struct {
27-
Remote bool
2827
ErrorCode uint32
28+
Remote bool
2929
}
3030

3131
func (e *GoAwayError) Error() string {

session.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,14 @@ func (s *Session) send() {
536536
if err := s.sendLoop(); err != nil {
537537
// Prefer the recvLoop error over the sendLoop error. The receive loop might have the error code
538538
// received in a GoAway frame received just before the TCP RST that closed the sendLoop
539-
//
540-
// Take the shutdownLock to avoid closing the connection concurrently with a Close call.
541539
s.shutdownLock.Lock()
542-
s.conn.Close()
543-
<-s.recvDoneCh
544-
if _, ok := s.recvErr.(*GoAwayError); ok {
545-
err = s.recvErr
540+
if s.shutdownErr == nil {
541+
s.conn.Close()
542+
<-s.recvDoneCh
543+
if _, ok := s.recvErr.(*GoAwayError); ok {
544+
err = s.recvErr
545+
}
546+
s.shutdownErr = err
546547
}
547548
s.shutdownLock.Unlock()
548549
s.close(err, false, 0)

0 commit comments

Comments
 (0)