diff --git a/main.go b/main.go index 77b8d24..13a226f 100644 --- a/main.go +++ b/main.go @@ -260,7 +260,6 @@ func main() { opts := []grpc.DialOption{ grpc.WithUserAgent(flUserAgent), - grpc.WithBlock(), } if flTLS && flSPIFFE { log.Printf("-tls and -spiffe are mutually incompatible") @@ -279,7 +278,8 @@ func main() { creds := alts.NewServerCreds(alts.DefaultServerOptions()) opts = append(opts, grpc.WithTransportCredentials(creds)) } else if flSPIFFE { - spiffeCtx, _ := context.WithTimeout(ctx, flRPCTimeout) + spiffeCtx, spiffeCancel := context.WithTimeout(ctx, flRPCTimeout) + defer spiffeCancel() source, err := workloadapi.NewX509Source(spiffeCtx) if err != nil { log.Printf("failed to initialize tls credentials with spiffe. error=%v", err) @@ -299,31 +299,30 @@ func main() { opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } - if flGZIP { - opts = append(opts, - grpc.WithCompressor(grpc.NewGZIPCompressor()), - grpc.WithDecompressor(grpc.NewGZIPDecompressor()), - ) - } + // 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 if flVerbose { log.Print("establishing connection") } connStart := time.Now() - dialCtx, dialCancel := context.WithTimeout(ctx, flConnTimeout) - defer dialCancel() - conn, err := grpc.DialContext(dialCtx, flAddr, opts...) + + // Use the new grpc.NewClient instead of deprecated DialContext + conn, err := grpc.NewClient(flAddr, opts...) if err != nil { - if err == context.DeadlineExceeded { - log.Printf("timeout: failed to connect service %q within %v", flAddr, flConnTimeout) - } else { - log.Printf("error: failed to connect service at %q: %+v", flAddr, err) - } + log.Printf("error: failed to create client for service at %q: %+v", flAddr, err) retcode = StatusConnectionFailure return } + connDuration := time.Since(connStart) - defer conn.Close() + defer func() { + if closeErr := conn.Close(); closeErr != nil { + log.Printf("warning: failed to close connection: %v", closeErr) + } + }() if flVerbose { log.Printf("connection established (took %v)", connDuration) }