Repository navigation
fix(client): name the server address in connection errors - #2535
Merged
tkircsi merged 1 commit intoNov 23, 2026
Merged
Conversation
A connection that reaches a listener that is not a gRPC server fails with "error reading server preface: ... looked like an HTTP/1.1 header" and nothing says which address was dialled. dirctl takes that address from a context, an environment variable or a flag, so it is easy to look for the problem in the wrong place. The client now adds two interceptors that append "(server <address>)" to Unavailable errors: when a unary call or stream is opened, and when an open stream sends or receives. The error stays a gRPC status with the same code and details, so callers that check the code see no change. Other errors pass through untouched. Fixes agntcy#2532 Signed-off-by: Uvesh Menpur <[email protected]>
tkircsi
approved these changes
Nov 23, 2026
tkircsi
left a comment
Contributor
There was a problem hiding this comment.
Thanks @uveshm003 ! Nice fix, thanks for the thorough testing notes. Exactly what #2532 asked for. The interceptor approach is a much nicer call than touching ~115 wrap sites, and the error-handling details are right: nil and io.EOF pass through untouched (so the errors.Is(err, io.EOF) stream-termination checks in client/ keep working), st.Proto() clones so status details survive, the code stays Unavailable, and the stream wrapper is stateless so concurrent SendMsg/RecvMsg on bidi streams is safe.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2532
The client wraps errors in about 115 places, so instead of editing each one,
client.Newadds a unary and a stream interceptor. They append(server <address>)toUnavailableerrors when a call or stream is opened, and when an open stream sends or receives. The error stays a gRPC status with the same code and details, so callers that checkstatus.Codesee no change. Other codes,io.EOFandnilpass through unchanged.The issue's case, reproduced with an HTTP/1.1 server on the dialled port:
A plain dial failure, which already names the address, now names it twice. I kept that rather than parse the message.
Testing
go test ./...inclient. The newTestConnectionErrorsNameTheServer(a stream and a unary call against an HTTP/1.1 server) fails onmain.go test ./...incli. It builds against the published client, so it doesn't exercise this change.golangci-lintv2.14.0 with the repo config: 0 issues.