-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added logs for reasons causing connection and transport close #5840
Changes from 1 commit
cfba279
2b055c6
c8bde09
06978d0
4633d06
30d51f7
dd3ccea
c2aa433
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,9 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts | |
// Any further errors will close the underlying connection | ||
defer func(conn net.Conn) { | ||
if err != nil { | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing connection due to error %v.", err) | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
conn.Close() | ||
} | ||
}(conn) | ||
|
@@ -244,6 +247,9 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts | |
<-newClientCtx.Done() // Block until connectCtx expires or the defer above executes. | ||
if connectCtx.Err() != nil { | ||
// connectCtx expired before exiting the function. Hard close the connection. | ||
if logger.V(logLevel) { | ||
logger.Infof("transport: closing connection due to connect context expiring.") | ||
easwars marked this conversation as resolved.
Show resolved
Hide resolved
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
conn.Close() | ||
} | ||
}(conn) | ||
|
@@ -396,6 +402,9 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts | |
err = <-readerErrCh | ||
} | ||
if err != nil { | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to error reading server preface: %v.", err) | ||
} | ||
t.Close(err) | ||
} | ||
}() | ||
|
@@ -447,7 +456,7 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts | |
err := t.loopy.run() | ||
if err != nil { | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: loopyWriter.run returning. Err: %v", err) | ||
logger.Errorf("transport: loopyWriter.run returned. Err: %v. Closing connection.", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not always required, but mostly makes sense to add the existing error string to the end of the new one. Also, could we skip There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loopyWriter returned? loopyWriter exited? loopyWriter finished? I went with third option. Line switched to: logger.Errorf("transport: loopyWriter exited. Closing connection. Err: %v", err). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept Err: %v in this and one below even though I switched ones above to consise errors ^^^ without an Err: and just : because I felt like these were important due to the "collection" point of these two. |
||
} | ||
} | ||
// Do not close the transport. Let reader goroutine handle it since | ||
|
@@ -965,6 +974,9 @@ func (t *http2Client) Close(err error) { | |
t.mu.Unlock() | ||
t.controlBuf.finish() | ||
t.cancel() | ||
if logger.V(logLevel) { | ||
logger.Infof("transport: calling Close on the conn within transport.Close.") | ||
} | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.conn.Close() | ||
channelz.RemoveEntry(t.channelzID) | ||
// Append info about previous goaways if there were any, since this may be important | ||
|
@@ -1007,6 +1019,9 @@ func (t *http2Client) GracefulClose() { | |
active := len(t.activeStreams) | ||
t.mu.Unlock() | ||
if active == 0 { | ||
if logger.V(logLevel) { | ||
logger.Infof("transport: closing transport because no active streams left to process in GracefulClose call.") | ||
} | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Close(ErrConnClosing) | ||
return | ||
} | ||
|
@@ -1255,7 +1270,11 @@ func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) { | |
id := f.LastStreamID | ||
if id > 0 && id%2 == 0 { | ||
t.mu.Unlock() | ||
t.Close(connectionErrorf(true, nil, "received goaway with non-zero even-numbered numbered stream id: %v", id)) | ||
err := connectionErrorf(true, nil, "received goaway with non-zero even-numbered numbered stream id: %v", id) | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to error in goaway handling: %v.", err) | ||
} | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Close(err) | ||
return | ||
} | ||
// A client can receive multiple GoAways from the server (see | ||
|
@@ -1273,7 +1292,11 @@ func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) { | |
// If there are multiple GoAways the first one should always have an ID greater than the following ones. | ||
if id > t.prevGoAwayID { | ||
t.mu.Unlock() | ||
t.Close(connectionErrorf(true, nil, "received goaway with stream id: %v, which exceeds stream id of previous goaway: %v", id, t.prevGoAwayID)) | ||
err := connectionErrorf(true, nil, "received goaway with stream id: %v, which exceeds stream id of previous goaway: %v", id, t.prevGoAwayID) | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to error in goaway handling: %v.", err) | ||
} | ||
t.Close(err) | ||
return | ||
} | ||
default: | ||
|
@@ -1296,7 +1319,11 @@ func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) { | |
t.prevGoAwayID = id | ||
if len(t.activeStreams) == 0 { | ||
t.mu.Unlock() | ||
t.Close(connectionErrorf(true, nil, "received goaway and there are no active streams")) | ||
err := connectionErrorf(true, nil, "received goaway and there are no active streams") | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to error in goaway handling: %v.", err) | ||
} | ||
t.Close(err) | ||
return | ||
} | ||
|
||
|
@@ -1602,7 +1629,11 @@ func (t *http2Client) reader(errCh chan<- error) { | |
continue | ||
} else { | ||
// Transport error. | ||
t.Close(connectionErrorf(true, err, "error reading from server: %v", err)) | ||
err := connectionErrorf(true, err, "error reading from server: %v", err) | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to connection level error %v.", err) | ||
} | ||
t.Close(err) | ||
return | ||
} | ||
} | ||
|
@@ -1661,7 +1692,11 @@ func (t *http2Client) keepalive() { | |
continue | ||
} | ||
if outstandingPing && timeoutLeft <= 0 { | ||
t.Close(connectionErrorf(true, nil, "keepalive ping failed to receive ACK within timeout")) | ||
err := connectionErrorf(true, nil, "keepalive ping failed to receive ACK within timeout") | ||
if logger.V(logLevel) { | ||
logger.Errorf("transport: closing transport due to error in keep alive handling: %v.", err) | ||
easwars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
t.Close(err) | ||
return | ||
} | ||
t.mu.Lock() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
ErrConnClosing
significant here? If not, can we instead return a meaningful error and capture all the exit reasons via a single log after loopy returns (which IIUC is already there)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like ErrConnClosing is used as a conditional/invariant anywhere in the system. Shoving this message/information into Error and logging at loopyWriter level sgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/transports/transport's/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done @easwars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm blind, and ErrConnClosing is used as a conditional in many many places at the control buf layer. Leaving this as is for now, unless you have a better suggestion.