Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the gRPC-related code to use newer, non-deprecated APIs and addresses leftover changes from PR #242. The changes modernize the connection handling and credential setup.
Key changes:
- Replaces deprecated
grpc.DialContextwithgrpc.NewClient - Updates to use
grpc.WithTransportCredentials(insecure.NewCredentials())instead of deprecatedgrpc.WithInsecure() - Fixes context leak by properly canceling the SPIFFE context
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Note: GZIP compression is now handled automatically by gRPC when available | ||
| // The deprecated WithCompressor/WithDecompressor options are no longer needed | ||
| // The -gzip flag is kept for backward compatibility but has no effect | ||
| _ = flGZIP // Suppress unused variable warning |
There was a problem hiding this comment.
The flGZIP flag is now silently ignored, which could confuse users who expect it to enable compression. Consider either: (1) logging a deprecation warning when the flag is used, or (2) documenting this behavior change in the PR description or changelog so users understand the flag no longer has an effect.
| _ = flGZIP // Suppress unused variable warning | |
| if flGZIP { | |
| log.Printf("warning: the -gzip flag is deprecated and no longer has any effect; gRPC compression is negotiated automatically") | |
| } |
There was a problem hiding this comment.
Ported over to
| conn, err := grpc.DialContext(dialCtx, flAddr, opts...) | ||
|
|
||
| // Use the new grpc.NewClient instead of deprecated DialContext | ||
| conn, err := grpc.NewClient(flAddr, opts...) |
There was a problem hiding this comment.
grpc.NewClient creates a client without immediately establishing a connection, but the code measures connDuration and logs 'connection established'. This is misleading since the actual connection happens lazily on the first RPC. The connection timing logic should be removed or updated to reflect that NewClient doesn't block to establish a connection.
There was a problem hiding this comment.
I'm still thinking we do some form of blocking dial and still let people configure dial timeout. What do you think?
There was a problem hiding this comment.
Indeed, current (on master) blocking while immediately establishing the connection may be deprecated for real-world applications, but for explicitly testing the grpc services health it may still be ok to do so. We just need to find how to elegantly do similar with the new NewClient() instead of deprecated grpc.DialContext().
There was a problem hiding this comment.
highly doubt this method will be removed anytime soon since it's a major breaking change for a lot of legacy code out there.
There was a problem hiding this comment.
The deprecation notices of both DialContext and WithBlock say:
Will be supported throughout 1.x.
(this is also clearly shown by linter)
There was a problem hiding this comment.
So, perhaps we should just add a comment why is this still being used and instruct linter to ignore it?
| defer func() { | ||
| if closeErr := conn.Close(); closeErr != nil { | ||
| log.Printf("warning: failed to close connection: %v", closeErr) | ||
| } | ||
| }() |
There was a problem hiding this comment.
The error handling for Close() is now more verbose than necessary. Since conn.Close() errors are typically not actionable and the program is already exiting, the simpler 'defer conn.Close()' pattern would be sufficient and more readable.
| defer func() { | |
| if closeErr := conn.Close(); closeErr != nil { | |
| log.Printf("warning: failed to close connection: %v", closeErr) | |
| } | |
| }() | |
| defer conn.Close() |
There was a problem hiding this comment.
This suggestion reverts this defer block addition and re-introduces the linter waning.
|
This PR fixes all remaining golangci-lint linter warnings from ...some may be needed and are detected as false positives. |
| opts = append(opts, | ||
| grpc.WithCompressor(grpc.NewGZIPCompressor()), | ||
| grpc.WithDecompressor(grpc.NewGZIPDecompressor()), | ||
| ) |
There was a problem hiding this comment.
There was a problem hiding this comment.
Ported to
Ported over from * #289 Co-Authored-By: Erazem Kokot <mail@erazemk.com>
Reviewable leftovers from overloaded PR
by @erazemk