Monedula

Markdown

Part VI · Reference

Kafka troubleshooting

InvalidRequestException (INVALID_REQUEST)

Kafka error · INVALID_REQUEST · not retriable

org.apache.kafka.common.errors.InvalidRequestException

The broker answered INVALID_REQUEST (error code 42) because the request breaks basic wire protocol rules: a field is missing, set where it must not be, or contradicts another field. Kafka says it most likely comes from a client library that built the request wrong, or from a request sent to an incompatible broker. The broker log and the error message say which rule the request broke.

Reproduce it in the playground

The moment it happensAn idempotent producer is refused under Ripcord. t+3.900s

At 3800 p-idem, an idempotent producer, sends k5. At 3850 it is refused with INVALID_REQUEST, and the record reaches no Agent. WarpStream's docs say idempotence and transactions must be off for Ripcord, but not how a producer that has them on is answered: the refusal and the code are the simulator's choices. INVALID_REQUEST is not retriable, so p-idem stops with an error.

Open at this step: step 3, An idempotent producer is refused under Ripcord

What it means

InvalidRequestException is how an Apache Kafka 4.4 broker or controller refuses a request that is well formed bytes but not a valid request. Its javadoc says it is thrown when a request breaks basic wire protocol rules, and the description of INVALID_REQUEST in Errors.java says it most likely occurs because the client library malformed the request or the message went to an incompatible broker, and points at the broker logs. Applications on the official clients rarely see it. It shows up with third-party clients, with tools that build requests by hand, and with admin calls whose fields are checked against each other: an incremental config change that sets a config to null instead of deleting it, the same config key twice for one resource, or a CreateTopics request that gives a manual replica assignment and also a partition count or a replication factor. The admin client sees the exception as the cause of the ExecutionException its request's future fails with; a producer gets it in its send callback, and the send is not retried. WarpStream, a Kafka-compatible system, limits idempotence and transactions in two places: its Ripcord page asks for both to be off, and its lightning topics page says such produce is rejected. Neither names an error code. In the simulator such a producer is refused with INVALID_REQUEST; the code is the simulator's choice in both cases, and so is the refusal under Ripcord. Scenarios 10.1.5 (Ripcord) and 10.1.6 (lightning topics) show it. StreamNative Ursa for Kafka, a Kafka-compatible system with diskless and disk topics in one cluster, names this code itself: a produce from a transactional producer to a diskless topic is rejected with INVALID_REQUEST, as Ursa does not support transactions on diskless topics yet (its docs say "coming soon"); disk topics take transactions as Apache Kafka does. Scenario 13.1.5 shows it.

Likely causes, most common first

  1. A client library that builds the request wrong. A third-party or outdated client, or a tool that writes requests by hand, sends a request whose fields break the protocol rules for its API version, or sends a request to an incompatible broker. With the official Java clients the error more often points at an admin call whose fields contradict each other.
  2. A config change with a null value or a repeated key. An incremental alter of a topic or broker config sets a config to null with an operation other than DELETE ("Null value not supported for"), or names the same config key twice for one resource ("Error due to duplicate config keys"). The broker refuses that resource's change before it reaches the controller; other resources in the same request still go through. A value the config does not accept is a different error, INVALID_CONFIG.
  3. A topic created with an assignment and counts. A CreateTopics request gives a manual replica assignment and also a partition count or a replication factor other than -1. The controller refuses the topic: with a manual assignment both must be -1, since the assignment already fixes them. The Java admin client's NewTopic sets them to -1 when it takes an assignment, so this comes from requests built some other way.
  4. WarpStream in the simulator: an idempotent producer under Ripcord or on a lightning topic. On a WarpStream cluster in the simulator with Ripcord on, while the control plane is unreachable, a producer with enable.idempotence=true or a transactional.id is refused with INVALID_REQUEST, and so is such a producer writing a lightning topic at any time. WarpStream's Ripcord page says both must be off, and its lightning topics page says such produce is rejected; neither names an error, so the code is the simulator's choice. Producers default to enable.idempotence=true since Kafka 3.0, so a producer is idempotent unless it sets enable.idempotence=false or, with enable.idempotence left unset, a conflicting setting (acks=0 or 1, retries=0, or max.in.flight.requests.per.connection above 5) turns it off.
  5. Ursa for Kafka: a transactional producer on a diskless topic. On an Ursa for Kafka cluster, a producer with a transactional.id that writes a diskless topic (ursa.storage.enable=true) gets INVALID_REQUEST on its first produce, and the record is not written. Idempotent producers without a transactional.id are supported on diskless topics. The same producer writing a disk topic of the same cluster commits its transactions.

How to fix it

  • Read the error message and the broker log: they name the rule the request broke, for example the config key with a null value.
  • Upgrade the client library, or align it with the broker version, if the request comes from a third-party or old client; report a reproducible case to its maintainers.
  • Remove a config with an incremental alter of type DELETE, or kafka-configs.sh --delete-config, instead of setting it to null, and name each config key once per resource.
  • Create a topic either with a partition count and a replication factor, or with a manual replica assignment and both left at -1, never with both.
  • On WarpStream with Ripcord, or for a lightning topic, set enable.idempotence=false and remove transactional.id on the producer; in the simulator, the refused record is not written, so send it again after the change.
  • On Ursa for Kafka, write transactions to a disk topic, or remove transactional.id on the producers of a diskless topic.

What not to do

  • Retrying the same request in a loop: the error is not retriable, and the request fails the same way until it changes.
  • Turning off idempotence on every producer to make the error go away: on Apache Kafka it is needed for no-duplicate retries, and only WarpStream's Ripcord and lightning topics ask for it off.

Does the client retry it?

No. INVALID_REQUEST (error code 42) is not retriable: InvalidRequestException extends ApiException, not RetriableException, and the same request gets the same answer every time. Change the request, or the client that builds it, then send it again.

Reproduce it in the simulator

Sources

All troubleshooting pages