英文:
Golang gRPC connection client side error - "error reading server preface: http2: frame too large"
问题
我正在写一个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 != "" {
// 将我们的证书添加到系统池中
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
命令向服务器发送请求并获得成功的响应。
英文:
I'm writing a go client to consume
conn, err := grpc.DialContext(ctx, serverAddr, grpc.WithBlock(), grpc.WithReturnConnectionError(), getTransportCredential(false))
The above call hangs until context timeout and returns the following error
failed to dial: context deadline exceeded: connection error: desc = "error reading server preface: http2: frame too large"
getTransportCredential(insecure bool)
is defined below
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)
}
Could you please help me solve this problem?
I can grpcurl
from my machine to the server and get a successful response.
答案1
得分: 2
HTTP/2的最大帧大小是2^14(16384)。你需要减小负载大小。请参考:https://www.rfc-editor.org/rfc/rfc7540#page-12,第76页。
英文:
maximum frame size of http/2 is 2^14 (16384)
you need to reduce yourself payload,
refer to: https://www.rfc-editor.org/rfc/rfc7540#page-12, page 76
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论