# rpc错误：代码=不可用 描述=连接错误：描述="传输：身份验证握手失败：tls：第一条记录看起来不像TLS握手"

- **ID:** `go/grpc-unavailable-connection-timeout`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

客户端使用TLS但服务器期望明文，反之亦然，导致握手失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0 | active | — | — |
| 1.1 | active | — | — |

## 解决方案

1. **Match TLS settings between client and server: either both use TLS or both use plaintext.** (95% 成功率)
   ```
   // Server with TLS
creds, err := credentials.NewServerTLSFromFile("server.crt", "server.key")
if err != nil { log.Fatal(err) }
s := grpc.NewServer(grpc.Creds(creds))
// Client with TLS
creds, err := credentials.NewClientTLSFromFile("ca.crt", "x")
if err != nil { log.Fatal(err) }
conn, err := grpc.Dial("localhost:8080", grpc.WithTransportCredentials(creds))
   ```
2. **Use insecure connection for development (not recommended for production).** (90% 成功率)
   ```
   conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure())
   ```

## 无效尝试

- **Ignore TLS configuration and assume automatic negotiation.** — gRPC does not auto-negotiate TLS; explicit configuration is required. (100% 失败率)
- **Use a self-signed certificate without proper validation.** — The server may reject self-signed certs if it requires a trusted CA. (70% 失败率)
