@@ -46,9 +46,9 @@ var nullMemoryManager = &nullMemoryManagerImpl{}
4646type Session struct {
4747 rtt int64 // to be accessed atomically, in nanoseconds
4848
49- // remoteGoAway indicates the remote side does
49+ // remoteGoAwayNormal indicates the remote side does
5050 // not want futher connections. Must be first for alignment.
51- remoteGoAway int32
51+ remoteGoAwayNormal int32
5252
5353 // localGoAway indicates that we should stop
5454 // accepting futher connections. Must be first for alignment.
@@ -205,8 +205,8 @@ func (s *Session) OpenStream(ctx context.Context) (*Stream, error) {
205205 if s .IsClosed () {
206206 return nil , s .shutdownErr
207207 }
208- if atomic .LoadInt32 (& s .remoteGoAway ) == 1 {
209- return nil , ErrRemoteGoAway
208+ if atomic .LoadInt32 (& s .remoteGoAwayNormal ) == 1 {
209+ return nil , ErrRemoteGoAwayNormal
210210 }
211211
212212 // Block if we have too many inflight SYNs
@@ -285,15 +285,15 @@ func (s *Session) AcceptStream() (*Stream, error) {
285285 }
286286}
287287
288- // Close is used to close the session and all streams.
289- // Attempts to send a GoAway before closing the connection. The GoAway may not actually be sent depending on the
290- // semantics of the underlying net.Conn. For TCP connections, it may be dropped depending on LINGER value or
291- // if there's unread data in the kernel receive buffer.
288+ // Close is used to close the session and all streams. It doesn't send a GoAway before
289+ // closing the connection.
292290func (s * Session ) Close () error {
293291 return s .close (ErrSessionShutdown , false , goAwayNormal )
294292}
295293
296294// CloseWithError is used to close the session and all streams after sending a GoAway message with errCode.
295+ // Blocks for ConnectionWriteTimeout to write the GoAway message.
296+ //
297297// The GoAway may not actually be sent depending on the semantics of the underlying net.Conn.
298298// For TCP connections, it may be dropped depending on LINGER value or if there's unread data in the kernel
299299// receive buffer.
@@ -315,7 +315,8 @@ func (s *Session) close(shutdownErr error, sendGoAway bool, errCode uint32) erro
315315 close (s .shutdownCh )
316316 s .stopKeepalive ()
317317
318- if sendGoAway {
318+ // Only send GoAway if we have an error code.
319+ if sendGoAway && errCode != goAwayNormal {
319320 // wait for write loop to exit
320321 // We need to write the current frame completely before sending a goaway.
321322 // This will wait for at most s.config.ConnectionWriteTimeout
@@ -814,7 +815,7 @@ func (s *Session) handleGoAway(hdr header) error {
814815 code := hdr .Length ()
815816 switch code {
816817 case goAwayNormal :
817- atomic .SwapInt32 (& s .remoteGoAway , 1 )
818+ atomic .SwapInt32 (& s .remoteGoAwayNormal , 1 )
818819 // Don't close connection on normal go away. Let the existing streams
819820 // complete gracefully.
820821 return nil
0 commit comments