From 4aed19495e803ebcc9c983c60f09b2e1d3ad122d Mon Sep 17 00:00:00 2001 From: sukun Date: Tue, 27 Aug 2024 12:56:01 +0530 Subject: [PATCH] fix race in write timeout --- session.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/session.go b/session.go index e31bef4..204b168 100644 --- a/session.go +++ b/session.go @@ -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)