Skip to content

Kafka 'Invalid Receive (size = 1195725856)': HTTP on a Kafka Port

Invalid receive (size = 1195725856 larger than 104857600) isn't a big message. It's the letters G, E, T and a space, read as a length. Something is speaking HTTP or TLS to your Kafka port. How to decode the number, find the sender, and fix it without touching the limit.

invalid-receive-size invalidreceiveexception socket-request-max-bytes health-checks kafka-brokers kafka-connections kafka kafka-errors
Gopi Gorantala
Reading Progress

On This Page

You've probably already raised socket.request.max.bytes. Maybe to 500 MB, because that's what one of the answers on page one says, and the warning kept coming anyway. Or it stopped, and something worse started that nobody has noticed yet.

Leave the limit alone. The broker isn't receiving a 1.1 GB request. It's receiving the word GET.

What the broker keeps logging

On a PLAINTEXT listener the broker writes a WARN, then the exception, and it repeats on a schedule that looks suspiciously like a health check:

WARN [SocketServer brokerId=2] Unexpected error from /10.0.3.17; closing connection
org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600)
    at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java)
    at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java)
    at org.apache.kafka.common.network.Selector.attemptRead(Selector.java)

That's the shape from a real report, trimmed; the line numbers depend on your version. The [SocketServer brokerId=2] prefix is what older ZooKeeper-mode brokers print. KRaft brokers label it with a listener type and node id instead, but the rest is identical.

The Invalid receive size larger than 104857600 message comes from one place in the Kafka source, NetworkReceive.readFrom, and the WARN line comes from Selector, which logs anything that isn't an IOException or an authentication failure as "Unexpected error … closing connection". Your applications see nothing. No producer error, no consumer error. The only symptom is a broker log full of these, sometimes thousands a day, and a monitoring dashboard showing a connection-close rate that never drops to zero.

Things worth noting before you change anything: which listener it's on (the port in the channel id, if your version prints one), the source address after from, and the interval between lines. Ten seconds apart, all from one address, is a probe. Random addresses at random times is a scanner.

Raising socket.request.max.bytes, and why it didn't help

It's the obvious move. The message says "larger than 104857600", 104857600 is the default socket.request.max.bytes (100 MiB, unchanged since 0.9), so you raise it. It's a read-only broker setting on every version I checked, so that's a server.properties change and a rolling restart.

The popular value is 500000000. Here's the problem: 1195725856 is bigger than 500000000. The GET warning survives the restart untouched. I've seen that "fix" credited in a thread where the real cause, a few answers down, was a TLS client hitting a PLAINTEXT port, which produces a smaller number. Raising the limit didn't fix that one either. It hid it, and I'll get to what it costs in a minute.

Get the same line in five minutes

Run this on a throwaway container, never a shared broker. I'm using apache/kafka:4.4.0 in KRaft mode with its default single-node config.

docker run -d --name kafka-lab -p 9092:9092 apache/kafka:4.4.0
sleep 15
curl -s --max-time 3 http://localhost:9092/ ; echo "curl exit: $?"
docker logs kafka-lab 2>&1 | grep -A1 "Unexpected error"

curl sends GET / HTTP/1.1, the broker reads the first four bytes as a request length, and the WARN plus InvalidReceiveException from above lands in the log. curl itself gets an empty reply because the broker closed the socket (exit code 52).

Now the TLS variant, which is the one that bites real applications:

openssl s_client -connect localhost:9092 -brief < /dev/null
docker logs kafka-lab 2>&1 | grep "Invalid receive" | tail -2

This time the size is a number starting with 3692, because a TLS ClientHello starts with bytes 16 03 03 01 or similar.

A Compose healthcheck is the most common way to cause this permanently. This is the lab shape I'd use to watch it repeat:

services:
  kafka:
    image: apache/kafka:4.4.0
    ports:
      - "9092:9092"
    healthcheck:
      test: ["CMD-SHELL", "curl -s http://localhost:9092 || exit 1"]  # HTTP against a Kafka port: one warning per interval
      interval: 10s
      retries: 3

A note on what I actually ran. The cloud sandbox I wrote this in had no Docker daemon, so the three blocks above are the commands and what the source says you'll get, not output I captured this session. What I did run is the decoding, on OpenJDK 21.0.13, and that's the part that cracks the case:

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

public class SizeDecoder {
    static int asKafkaSize(byte[] b) {
        return ByteBuffer.wrap(b, 0, 4).getInt(); // exactly what the broker does with the first 4 bytes
    }

    static void show(String label, byte[] b) {
        System.out.printf("%-28s first bytes %02x %02x %02x %02x -> size = %d%n",
                label, b[0], b[1], b[2], b[3], asKafkaSize(b));
    }

    public static void main(String[] args) throws Exception {
        for (String s : new String[]{"GET / HTTP/1.1", "POST /x HTTP/1.1", "HEAD / HTTP/1.1",
                "PUT /x HTTP/1.1", "PRI * HTTP/2.0", "SSH-2.0-OpenSSH_9.6"}) {
            show("\"" + s + "\"", s.getBytes(StandardCharsets.US_ASCII));
        }
        for (String proto : new String[]{"TLSv1.2", "TLSv1.3"}) {
            SSLContext ctx = SSLContext.getInstance("TLS");
            ctx.init(null, null, null);
            SSLEngine engine = ctx.createSSLEngine("broker-1", 9092);
            engine.setUseClientMode(true);
            engine.setEnabledProtocols(new String[]{proto});
            ByteBuffer out = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());
            engine.beginHandshake();
            engine.wrap(ByteBuffer.allocate(0), out); // a real ClientHello, as a Java Kafka client with security.protocol=SSL would send
            out.flip();
            byte[] hello = new byte[out.remaining()];
            out.get(hello);
            show("JSSE ClientHello " + proto + " (" + hello.length + " B)", hello);
        }
    }
}
$ java SizeDecoder.java
"GET / HTTP/1.1"             first bytes 47 45 54 20 -> size = 1195725856
"POST /x HTTP/1.1"           first bytes 50 4f 53 54 -> size = 1347375956
"HEAD / HTTP/1.1"            first bytes 48 45 41 44 -> size = 1212498244
"PUT /x HTTP/1.1"            first bytes 50 55 54 20 -> size = 1347769376
"PRI * HTTP/2.0"             first bytes 50 52 49 20 -> size = 1347569952
"SSH-2.0-OpenSSH_9.6"        first bytes 53 53 48 2d -> size = 1397966893
JSSE ClientHello TLSv1.2 (265 B) first bytes 16 03 03 01 -> size = 369296129
JSSE ClientHello TLSv1.3 (313 B) first bytes 16 03 03 01 -> size = 369296129

Teardown: docker rm -f kafka-lab. Nothing else to clean up; no topics or volumes were created.

Find who's knocking on 9092

  1. Decode the number first. Convert it to hex and read the bytes. printf '%08x\n' 1195725856 gives 47455420, which is ASCII for GET. If the bytes are printable letters, it's a text protocol (HTTP, SSH, Redis, SMTP). If they start with 16 03, it's a TLS handshake. That rules out "a client sent a big batch" in about five seconds.
  2. Take the source IP from the WARN line and find its owner.

bash docker network inspect bridge --format '{{range .Containers}}{{.Name}} {{.IPv4Address}}{{"\n"}}{{end}}' kubectl get pods -A -o wide | grep 10.0.3.17

If the IP is the Docker bridge gateway or the node itself, it's a healthcheck running on the host or inside the broker container. If it's a pod, you have your culprit. If it's a load balancer's address, look at the load balancer's health check settings, not your apps. This step needs access to the Docker host or kubectl rights to list pods; on a managed service you'll get the IP and not much else.

  1. Check the interval. Count lines per minute with docker logs --since 10m kafka 2>&1 | grep -c "Invalid receive". Six a minute from one address matches a 10-second probe. A burst of different sizes from one address is a port scanner. One line at every deploy is an app starting up with the wrong security.protocol.
  2. Check which listener it hit. A TLS client on the SSL listener can't cause this, and an HTTP probe on an SSL listener fails the handshake instead ("Failed authentication … SSL handshake failed", see the SSL handshake post). So this exact WARN almost always points at a PLAINTEXT listener.

What each step ruled out: step 1 kills the "too-large message" theory, step 2 tells you whether it's infra or an application, step 3 separates probes from scanners from clients, step 4 tells you which port to stare at.

1195725856 is the word GET

The cause in one sentence: something that isn't a Kafka client sent bytes to a Kafka port, and the broker read the first four of them as a request length.

Every Kafka request on the wire starts with a 4-byte big-endian integer saying how many bytes follow. The broker's network thread reads exactly four bytes, turns them into an int, and checks it in NetworkReceive.readFrom: negative means Invalid receive (size = N), bigger than maxSize means Invalid receive (size = N larger than M). On a PLAINTEXT listener maxSize is socket.request.max.bytes. InvalidReceiveException extends KafkaException, not IOException, which is why Selector logs it at WARN as "Unexpected error" and not at DEBUG as a plain disconnect. Then it closes the socket. That's the whole story on the broker side.

The three checks, against the lab:

  • ✅ The number decodes to the probe's own bytes: 47 45 54 20 is GET, which my decoder run shows exactly.
  • ✅ Take the curl healthcheck out of the Compose file and the warnings stop at the next interval; put it back and they return at the same 10-second rhythm. (Commands above; I couldn't run the broker in this sandbox, so verify this on yours.)
  • ✅ It explains every R1 symptom: one source address, a fixed interval, no application errors (no Kafka client is involved), and a size that never changes.

The surprise, for me, was what happens when you raise the limit past the number. With a TLS client on a PLAINTEXT port, the "size" is about 369 MB. Set socket.request.max.bytes=500000000 and the check passes, so the broker goes ahead and asks for a 369 MB buffer for that connection. With the default queued.max.request.bytes=-1 there's no memory pool, so it's a straight heap allocation, then the broker waits for 369 MB that will never arrive while the client gives up. Repeat on every reconnect from every misconfigured client. The loud warning turns into quiet heap pressure, and the next thing in the log might be an OutOfMemoryError: Java heap space on the broker. The limit is there to stop exactly that.

Every other way to get an invalid receive size

Cause How to confirm it Quick tell
HTTP healthcheck or probe on the Kafka port (Compose curl, Kubernetes httpGet, cloud load balancer HTTP check) source IP is the host, kubelet node or LB; fixed interval 1195725856 (GET) or 1212498244 (HEAD)
Prometheus or another scraper pointed at 9092 instead of the JMX exporter port scrape config target GET, every scrape interval
A Kafka client with security.protocol=SSL or SASL_SSL on a PLAINTEXT listener client config dump at startup 3692… (TLS ClientHello)
An HTTP client pointed at the broker by mistake, like schema.registry.url=http://kafka:9092 the app's Schema Registry or REST settings 1347375956 (POST)
HTTP/2 or gRPC client on the port client config 1347569952 (PRI)
Security or port scanner many sizes, one source, in bursts SSH-, random binary, negative sizes
A real client sending a request bigger than 100 MiB (someone raised max.request.size very high) the number decodes to binary nonsense and is plausible, say 157286400 producer max.request.size above the broker limit

On a SASL listener you won't see this text at WARN. The SASL authenticator uses a much smaller limit, sasl.server.max.receive.size (default 524288, 512 KiB), wraps the exception, and the broker logs it at INFO as a failed authentication with "Failing SASL authentication due to invalid receive size". Same cause, different line, and it also bumps your failed-authentication metric, which can trigger a security alert for what's really a misconfigured health check. The SASL authentication post covers the real credential failures.

The mirror image, a PLAINTEXT Kafka client talking to a TLS port, is a different problem in the other direction: the client reads the server's TLS alert as a size (352518912 is 15 03 03 00) and you see Bootstrap broker disconnected on the client. Not this article, same family.

The last row is the only case where the limit itself matters, and even then the fix is usually smaller records, see RecordTooLargeException.

Point the probe somewhere else

Fix the sender. Don't change the broker.

For a Compose healthcheck, swap HTTP for something that speaks Kafka. The apache/kafka image ships the CLI tools under /opt/kafka/bin:

    healthcheck:
      test: ["CMD-SHELL", "/opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092 > /dev/null 2>&1"]
      interval: 10s
      timeout: 10s
      retries: 5

It costs a JVM start per check, so it's slower than curl (a couple of seconds). If that bothers you, nc -z localhost 9092 checks the port is open without sending a byte, at the cost of not proving the broker can answer.

For Kubernetes, replace the httpGet probe on 9092 with a tcpSocket probe, or an exec probe running the same CLI:

readinessProbe:
  tcpSocket:
    port: 9092
  periodSeconds: 10

For a load balancer, change its health check protocol from HTTP to TCP. For Prometheus, scrape the JMX exporter's port (whatever you set on its -javaagent line), never the listener.

For a Kafka client with the wrong protocol, make security.protocol match the listener. In Spring Boot that's spring.kafka.security.protocol (or per client under spring.kafka.producer.security.protocol), and watch for spring.kafka.ssl.* properties left over from another environment. On the client side the same mistake usually shows up as a hang or a disconnect warning, so you'll find it from the broker log first.

For schema.registry.url or any REST URL pointing at a broker, fix the URL. Schema Registry listens on 8081 by default, not 9092.

Fixes that aren't fixes: raising socket.request.max.bytes (covered above, it trades a warning for heap), turning the Selector logger down to ERROR (you lose the evidence and keep the problem), and opening the listener to the world so the "real" health check passes.

Check before you close the ticket

After the change, watch the log for at least three probe intervals:

docker logs --since 2m kafka 2>&1 | grep -c "Invalid receive"
docker inspect --format '{{.State.Health.Status}}' kafka

You want 0 from the first command and healthy from the second. On Kubernetes, kubectl describe pod should show the probe passing with no restarts, and on a broker with JMX the connection-close rate on that listener should drop to whatever your real clients produce. If the count is lower but not zero, there's a second sender; go back to step 2 with the new source IP.

Health checks that speak Kafka

The habit that prevents the whole class: nothing talks to a broker port unless it speaks the Kafka protocol. Health checks, scrapers and load balancers get either a TCP check or a real Kafka request.

If your app needs its own readiness check against Kafka, do it with the Admin client, not a socket:

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.DescribeClusterOptions;
import org.apache.kafka.common.Node;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class KafkaReadiness {
    public static void main(String[] args) {
        String bootstrap = args.length > 0 ? args[0] : "localhost:9092";
        Map<String, Object> conf = Map.of(
                AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrap,
                AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, 3000,
                AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, 5000);
        int exitCode;
        try (Admin admin = Admin.create(conf)) {
            Collection<Node> nodes = admin.describeCluster(new DescribeClusterOptions().timeoutMs(5000))
                    .nodes().get(6, TimeUnit.SECONDS);
            System.out.println("ready: " + nodes.size() + " broker(s)");
            exitCode = 0;
        } catch (Exception e) {
            System.err.println("not ready: " + e);
            exitCode = 1;
        }
        System.exit(exitCode);
    }
}

Alert on it, too. A grep-based log alert for InvalidReceiveException with a threshold of a handful per hour catches a new bad probe the day someone adds it, and a jump in failed authentications on SASL listeners with no matching login errors from your apps is the same problem in disguise.

Version note: the message text and the 104857600 default have been the same across every line I could find, from 2.x reports to the current trunk source. sasl.server.max.receive.size exists from 3.3 at least (its 524288 default shows in the 3.3 to 4.4 config references). The prefix on the WARN line is the part that changes between ZooKeeper-mode and KRaft brokers, so grep for Invalid receive, not the prefix.

What I checked for this one: both throw sites in NetworkReceive, the Selector catch block that picks WARN over DEBUG, the SASL authenticator's wrapping, the defaults for the three settings involved, and the decoded bytes for six text protocols and two real TLS handshakes. I didn't have a broker to run in this sandbox; the decoding is from my own run, the broker behaviour is from the source.

If you're in production right now

  • Copy one WARN line with its source IP before anything restarts.
  • Decode the size: printf '%08x\n' <size> and read it as ASCII.
  • Find the owner of the source IP (container, pod, load balancer, scanner).
  • Change that sender's protocol or target. Leave socket.request.max.bytes where it is.

If the number decodes to binary and the source is one of your producers, it's a genuinely large request: read the RecordTooLargeException post before touching any size limit. If your clients are also failing to connect, start from which Kafka connection error is it, and if you're wiring up Docker from scratch, Kafka in Docker Compose for host and containers has a healthcheck that doesn't do this. For reading the rest of a broker or client stack trace, see how to read a Kafka error.

If you only read this bit

  • Invalid receive (size = 1195725856 larger than 104857600) is GET read as a length. Something sent HTTP to a Kafka port.
  • Sizes starting 3692… are a TLS ClientHello: a client with security.protocol=SSL on a PLAINTEXT listener.
  • The WARN line's source IP tells you who. It's usually a health check, a scraper or a load balancer.
  • Raising socket.request.max.bytes doesn't fix it, and past 369 MB it starts costing broker heap.
  • Done means zero Invalid receive lines over a few probe intervals and a healthcheck that speaks Kafka.

FAQ

What does "Invalid receive size larger than 104857600" mean in Kafka?

The broker read the first four bytes of an incoming request as its length and got a number above socket.request.max.bytes (104857600 bytes by default). In practice the bytes are almost always text or a TLS header from a non-Kafka client, such as 1195725856 for GET. It's logged on the broker only; your Kafka clients aren't affected.

Should I increase socket.request.max.bytes to fix InvalidReceiveException?

No, not unless the number decodes to binary and comes from one of your own producers. For HTTP probes the size is above 1 GB, so typical increases don't even stop the warning, and for TLS clients a higher limit makes the broker allocate a heap buffer of about 369 MB per connection attempt.

Why does my Kafka broker log "Unexpected error from /IP; closing connection"?

That WARN comes from the broker's Selector for any error that isn't a plain disconnect or an authentication failure, and on PLAINTEXT listeners it's most often followed by InvalidReceiveException. The IP after from is the sender. Find what runs there and you've found the cause.

How do I health check a Kafka broker in Docker or Kubernetes without HTTP?

Use a TCP check (nc -z in Compose, a tcpSocket probe in Kubernetes) to see the port is open, or run kafka-broker-api-versions.sh --bootstrap-server localhost:9092 for a check that the broker actually answers Kafka requests. Kafka listeners don't speak HTTP, so any curl or httpGet probe against them produces this warning.

invalid-receive-sizeinvalidreceiveexceptionsocket-request-max-byteshealth-checkskafka-brokerskafka-connectionskafkakafka-errors

Staff engineer architecting Kafka and Flink platforms for banking, where a dropped event is a reconciliation break, not a retry. Through javahandbook.com, I share production-tested guidance on building reliable event-driven systems.

Comments