isConnectionError returns true if the error indicates the remote endpoint is unreachable (connection refused, reset, gRPC Unavailable). Returns false for timeouts and deadline exceeded — those may indicate a busy server, not a dead one.
(err error)
| 13 | // unreachable (connection refused, reset, gRPC Unavailable). Returns false for |
| 14 | // timeouts and deadline exceeded — those may indicate a busy server, not a dead one. |
| 15 | func isConnectionError(err error) bool { |
| 16 | if err == nil { |
| 17 | return false |
| 18 | } |
| 19 | |
| 20 | // gRPC Unavailable = server not reachable (covers connection refused, DNS, TLS errors) |
| 21 | if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable { |
| 22 | return true |
| 23 | } |
| 24 | |
| 25 | // Syscall-level connection errors |
| 26 | if errors.Is(err, syscall.ECONNREFUSED) || errors.Is(err, syscall.ECONNRESET) { |
| 27 | return true |
| 28 | } |
| 29 | |
| 30 | // Fallback string matching for wrapped errors that lose the typed error |
| 31 | msg := err.Error() |
| 32 | return strings.Contains(msg, "connection refused") || |
| 33 | strings.Contains(msg, "connection reset") || |
| 34 | strings.Contains(msg, "no such host") |
| 35 | } |
no test coverage detected