fix(broker): auto-close broken connections#3412
Conversation
Signed-off-by: DCjanus <[email protected]>
Signed-off-by: DCjanus <[email protected]>
Signed-off-by: DCjanus <[email protected]>
Signed-off-by: DCjanus <[email protected]>
6ab92b9 to
0960b52
Compare
6e747d2 to
f69de2e
Compare
dnwe
left a comment
There was a problem hiding this comment.
Thanks for raising this PR!
There's a pattern of:
if shouldCloseBrokerConn(err) {
b.connErr = err
_ = b.closeInnerLocked()
// …
}(occasionally with a return at the // ... and occasionally not)
I wonder if we should make this a dedicated func on broker to avoid the repetition?
b.maybeCloseBrokerConn(err)
I also wasn't totally sure on the naming of closeInnerLocked, although I couldn't immediately think of a better name for it
Yeah, the common pattern in Go is usually to provide a |
I’m considering renaming Does that feel clear enough, or would you prefer something more explicit like |
5922d29 to
506ed17
Compare
Just introduced a |
dnwe
left a comment
There was a problem hiding this comment.
Thanks again for this PR. Logically the changes look good now. Some of the code comments are a little verbose, if you’re using agent assistance then maybe prompt it to clean those up:
only add comments when they explain why, not what - if the code needs a comment to explain what it does, rewrite the code to be clearer
f81c761 to
6f8546b
Compare
|
I went through the comments pass and made the notes shorter. The comment-trimming commit is a138d2c. 🤝 About the extra comments: I do use an agent, but I’m still getting familiar with this codebase. I asked the agent to explain parts of the design so I could check its output. That made it add more comments than needed for reviewers. I removed most of them and kept only the useful ones. If I removed too much, please feel free to adjust the comments directly. There was earlier feedback that If you prefer a different name or any other changes, please feel free to push directly to this branch — maintainer edits are enabled. |
fbdeb5b to
b6aaa81
Compare
06b3458 to
2b38cb1
Compare
|
LGTM. I've rebase the commits into a clean set and will approve and merge once the FV checks have all passed 👍🏻 |
dnwe
left a comment
There was a problem hiding this comment.
Thanks again, great contribution!
Background
Approach
shouldCloseBrokerConnto detect fatal transport errors inside Broker.closeInnerLockedto close/reset the connection and preserve the original error inconnErr, so callers can re-establish via explicitOpen().Changes
broker.go: auto-close and reset state on transport errors during ApiVersions negotiation andsendAndReceive; extract lock-held helpercloseInnerLocked.TestBrokerOpenApiVersionsTransportErroruses a custom dialer to reliably hit EOF, ensuring the connection is marked unusable andOpenis retryable.TestFuncAdminNetworkErrorClosesControllerConnectioninjects a one-shotreset_peervia toxiproxy to proveOpentriggers reconnection and metadata requests recover; adds proxy helper utilities.docker compose down/rmalways includes--profile zookeeperto avoid leftovers with Kafka < 4.github.com/klauspost/compress→ 1.18.2,golang.org/x/sync→ 0.18.0 (no behavior change).Verification
go test -run '^TestBrokerOpenApiVersionsTransportError$' -count=1 ./...go test -tags functional -run '^TestFuncAdminNetworkErrorClosesControllerConnection$' -count=1 ./...Compatibility
No breaking API changes; only closes broken connections earlier on transport errors and relies on explicit
Opento reconnect.