Golang gRPC 连接客户端错误 - “错误读取服务器前言:http2:框架太大”

noo*_*dev 6 go google-cloud-platform http2 grpc google-cloud-run

我正在写一个 go 客户端来消费

conn, err := grpc.DialContext(ctx, serverAddr, grpc.WithBlock(), grpc.WithReturnConnectionError(), getTransportCredential(false))
Run Code Online (Sandbox Code Playgroud)

上面的调用挂起直到上下文超时并返回以下错误

failed to dial: context deadline exceeded: connection error: desc = "error reading server preface: http2: frame too large"
Run Code Online (Sandbox Code Playgroud)

getTransportCredential(insecure bool)定义如下

func getTransportCredential(insecure bool) grpc.DialOption {
    if insecure {
        return grpc.WithTransportCredentials(insecure2.NewCredentials())
    }

    rootCAs, err := x509.SystemCertPool()
    if err != nil {
        panic(err)
    }
    if rootCAs == nil {
        fmt.Println("SystemCertPool is nil")
        rootCAs = x509.NewCertPool()
    }

    caCert := `-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----`

    if caCert != "" {
        // Append our cert to the system pool
        if ok := rootCAs.AppendCertsFromPEM([]byte(caCert)); !ok {
            fmt.Println("Couldn't add cert to the cert pool")
        }
    }

    creds := credentials.NewClientTLSFromCert(rootCAs, "")
    fmt.Printf("%+v\n", creds.Info())
    return grpc.WithTransportCredentials(creds)
}
Run Code Online (Sandbox Code Playgroud)

你能帮我解决这个问题吗?

我可以grpcurl从我的机器到服务器并获得成功的响应。

Too*_*You 2

http/2 的最大帧大小为 2^14 (16384)在此输入图像描述 你需要减少自己的负载,

参考: https: //www.rfc-editor.org/rfc/rfc7540#page-12,第76页

  • 感谢您的回复。由于某种原因,我认为该错误没有正确代表实际问题。我必须 ```os.Unset(...)``` HTTP 和 HTTPS 代理环境变量,然后客户端就能够连接到服务了。 (3认同)