# rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:8080: connect: connection refused"

- **ID:** `go/grpc-unavailable-connection-refused`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

gRPC client attempts to connect to a server that is not running or the port is incorrect.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## Workarounds

1. **Ensure the gRPC server is running and accessible at the configured address.** (95% success)
   ```
   Check server health by verifying the process is active and listening on the expected port. Use netstat or lsof to confirm.
   ```
2. **Implement a health check and retry logic with circuit breaker.** (85% success)
   ```
   conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*4)))
if err != nil {
    log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
   ```

## Dead Ends

- **Retry the connection with exponential backoff without checking server status.** — If the server is down, retries will keep failing until the server is up. This wastes resources and delays detection. (90% fail)
- **Increase the dial timeout in client configuration.** — A longer timeout does not fix the fundamental issue of server unavailability; it just delays the error. (80% fail)
