Golang gRPC Connection Client Side Error - "Error Reading Server Preface: Http2: Frame Too Large"

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 Answer

maximum frame size of http/2 is 2^14 (16384) you need to reduce yourself payload,

refer to: , page 76

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest