go network_error ai_generated true

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

rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: first record does not look like a TLS handshake"

ID: go/grpc-unavailable-connection-timeout

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-07-22首次发现

版本兼容性

版本状态引入弃用备注
1.0 active
1.1 active

根因分析

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

English

The client is using TLS but the server expects plaintext, or vice versa, causing a handshake failure.

generic

解决方案

  1. 95% 成功率 Match TLS settings between client and server: either both use TLS or both use plaintext.
    // 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. 90% 成功率 Use insecure connection for development (not recommended for production).
    conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure())

无效尝试

常见但无效的做法:

  1. Ignore TLS configuration and assume automatic negotiation. 100% 失败

    gRPC does not auto-negotiate TLS; explicit configuration is required.

  2. Use a self-signed certificate without proper validation. 70% 失败

    The server may reject self-signed certs if it requires a trusted CA.