Skip to content

Fix gRPC client error handling and health check timeout context#23

Open
alienx5499 wants to merge 1 commit intodrand:masterfrom
alienx5499:fix/grpc-client-error-handling
Open

Fix gRPC client error handling and health check timeout context#23
alienx5499 wants to merge 1 commit intodrand:masterfrom
alienx5499:fix/grpc-client-error-handling

Conversation

@alienx5499
Copy link
Contributor

Problem

Two issues in grpc/grpc.go:

  1. NewClient ignores error from grpc.NewClient — if the call fails, the error is logged but not returned. The function continues with a nil conn, and proto.NewPublicClient(conn) will panic.

  2. Health check retry bypasses timeout — in Check(), the first attempt uses tctx (with timeout), but the retry falls back to the original ctx (no timeout). This means the retry can hang indefinitely, defeating the configured healthTimeout.

Changes

grpc/grpc.go

  • Return the error from grpc.NewClient instead of continuing with a nil connection.
  • Use tctx (timeout context) for the health check retry instead of the parent ctx.

grpc/grpc_test.go

  • TestNewClient_InvalidAddress — verifies NewClient returns an error for invalid addresses.
  • TestCheck_CancelledContext — verifies Check respects context cancellation.

Testing

go test ./... -timeout 60s

All existing and new tests pass. No behavior changes for valid inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant