Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

A Go gRPC client fails at connect time with http2: frame too large

Your error

error reading server preface: http2: frame too large2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The port expects TLS, but the client dials it with insecure credentials

Dial with TLS transport credentials from the credentials package.

Fix
import (
    "crypto/tls"

    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
)

conn, err := grpc.NewClient("api.example.com:443",
    grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

error reading server preface: http2: frame too large means the grpc-go client spoke plaintext HTTP/2 and got back something else, usually an HTTP/1.1 reply whose first bytes, HTT, decode as a frame length near 4.7 MB. The usual reasons: insecure credentials against a TLS port, a non-gRPC port, or a proxy without HTTP/2. Applies to grpc-go 1.85 with x/net 0.60.

  • Applies to grpc-go 1.85.0, golang.org/x/net 0.60, Go 1.26 and 1.27, nginx with ngx_http_grpc_module
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask the same host and port two questions with curl: what answers a plain HTTP request, and does TLS work there. If the HTTPS request gets a status line, the port expects TLS (cause 1). If only plain HTTP answers and it is your web app or a metrics page, the port is wrong (cause 2). If a proxy such as nginx answers on a plain port that should carry gRPC, look at cause 3.

Run this first
curl -si http://api.example.com:443/ | head -5
curl -sI https://api.example.com:443/ | head -1

Then find the line you see in this list and open its fix:

  1. 1The port expects TLS, but the client dials it with insecure credentialsThe code passes insecure.NewCredentials() (or the older grpc.WithInsecure()) while the target is port 443, an ingress or a cloud load balancer, and the HTTPS curl in the first step succeeds
  2. 2The address points at an HTTP/1.1 port rather than the gRPC listenerThe plain curl gets a normal answer from a web server, REST gateway or metrics endpoint, and the error text ends with note that the frame header looked like an HTTP/1.1 header
  3. 3A reverse proxy in front of the server listens without HTTP/2 or uses proxy_passThe plain curl reply carries a Server: nginx header (or another proxy's name), and the proxy config forwards with proxy_pass or has no http2 on its listen block

What does the error look like?

  • error reading server preface: http2: frame too large
  • error reading server preface: http2: failed reading the frame payload: http2: frame too large, note that the frame header looked like an HTTP/1.1 header
  • connection error: desc = "error reading server preface: http2: frame too large"

Cause 1 of 3

The port expects TLS, but the client dials it with insecure credentials

You seeThe code passes insecure.NewCredentials() (or the older grpc.WithInsecure()) while the target is port 443, an ingress or a cloud load balancer, and the HTTPS curl in the first step succeeds

Check

In this case the frame too large error at the server preface comes from a plaintext client meeting a TLS listener. A front end such as nginx recognises a regular request arriving on its HTTPS port (its error code 497) and answers it with an HTTP error response, so the first bytes the client reads are HTTP text instead of a SETTINGS frame.

Check
grep -rnE "insecure.NewCredentials|WithInsecure" --include=*.go .

Fix

Dial with TLS transport credentials from the credentials package. An empty tls.Config verifies the server against the host's root CA set, which fits public endpoints; for a private CA, load its certificate with NewClientTLSFromFile.

Fix
import (
    "crypto/tls"

    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
)

conn, err := grpc.NewClient("api.example.com:443",
    grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))

Verify

The client completes its first RPC, and its output no longer mentions the server preface.

Verify
go run . 2>&1 | grep -c "server preface"

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

The address points at an HTTP/1.1 port rather than the gRPC listener

You seeThe plain curl gets a normal answer from a web server, REST gateway or metrics endpoint, and the error text ends with note that the frame header looked like an HTTP/1.1 header

Check

The grpc-go issue tracker walks through this exact path: an HTTP/1.1 server reads the HTTP/2 client preface as a request with an unknown method and usually answers with an HTTP/1.1 status line such as 405. The client takes the first three bytes, HTT, as the length of the SETTINGS frame (0x485454) and gives up. Since early 2025, golang.org/x/net appends the HTTP/1.1 note to make this case recognisable.

Check
curl -si http://api.example.com:8080/ | head -3

Fix

Find the port the gRPC server actually listens on (its grpc.NewServer listener, a Kubernetes Service port named for gRPC, or the service's documentation) and dial that one. Servers that expose both REST and gRPC usually use two different ports.

Fix
conn, err := grpc.NewClient("api.example.com:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))

Verify

Run the client again; the RPC returns data or a gRPC status code such as Unimplemented, which proves an HTTP/2 gRPC server answered.

Verify
go run .

Confirmed by github.com

Did this fix it?

Cause 3 of 3

A reverse proxy in front of the server listens without HTTP/2 or uses proxy_pass

You seeThe plain curl reply carries a Server: nginx header (or another proxy's name), and the proxy config forwards with proxy_pass or has no http2 on its listen block

Check

A proxy that only speaks HTTP/1.1 on the client side answers the HTTP/2 preface just as an HTTP/1.1 app would. nginx needs its HTTP/2 module for gRPC: the documented setup enables http2 on the server block and forwards with grpc_pass (grpcs:// for TLS to the backend), not proxy_pass.

Check
grep -rnE "listen|http2|grpc_pass|proxy_pass" /etc/nginx/

Fix

Turn on HTTP/2 for the listener and hand requests to the backend with grpc_pass, then reload nginx with your usual service command.

Fix
server {
    listen 9000;
    http2 on;

    location / {
        grpc_pass grpc://127.0.0.1:50051;
    }
}

Verify

After the reload, the client's RPC passes through the proxy and returns a reply.

Verify
go run .

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Read transport security from configuration (TLS on or off per environment) instead of hard-coding insecure.NewCredentials().
  • Name the gRPC port explicitly in Kubernetes Services and client configs, apart from any REST or metrics port.
  • Keep golang.org/x/net current in go.mod so HTTP/1.1 replies produce the clearer error note.
  • Add a start-up health check that runs one RPC, so a TLS or port mismatch fails at deploy time.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, stegnor.com.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.