Golang gRPC连接客户端出错 - "error reading server preface: http2: frame too large"。

6

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

conn, err := grpc.DialContext(ctx, serverAddr, grpc.WithBlock(), grpc.WithReturnConnectionError(), getTransportCredential(false))

上述调用会一直等待,直到超时并返回以下错误。
failed to dial: context deadline exceeded: connection error: desc = "error reading server preface: http2: frame too large"

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)
}

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

我可以使用grpcurl从我的计算机连接到服务器并获得成功的响应。

1个回答

2

2
感谢您的回复。由于某种原因,我认为错误没有正确地表示实际问题。我必须使用os.Unset(...)命令取消HTTP和HTTPS代理环境变量,然后客户端才能连接到服务。 - noob-dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接