question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KafkaJSProtocolError: The broker received an out of order sequence number

See original GitHub issue

Hi

I have a single producer:

const producer = kafka.producer({
  allowAutoTopicCreation: false,
  idempotent: true,
  maxInFlightRequests: 1
});

As you can see, I’m using the idempotent feature introduced in https://github.com/tulios/kafkajs/pull/203 I’m also forcing the maxInFlightRequests to 1

It works fine when my producer sends messages to the kafka server at a slow pace. By that I mean no requests are stored in the RequestQueue.

But during spike in activity, sometimes messages are automatically sent in batch. Kafka then returns the following error:

ERROR [ReplicaManager broker=0] Error processing append operation on partition TOPIC (kafka.server.ReplicaManager)
kafka_1                 | org.apache.kafka.common.errors.OutOfOrderSequenceException: Out of order sequence number for producerId 74: 158 (incoming seq. number), 156 (current end sequence number)

In this bug case, we have 156158 jump, because 2 messages where sent in the batch.

According the kafka java code, it expects only a 1 unit jump so 156157:

https://github.com/apache/kafka/blob/fecb977b257888e2022c1b1e04dd7bf03e18720c/core/src/main/scala/kafka/log/ProducerStateManager.scala#L241-L251

My current understanding/intuition, is that the firstSequence number should always be incremented by 1 and not by the number of messages present in the batch request.

Which roughly means that the updateSequence method of the EOSManager should not take an increment param but always increment by 1 only. https://github.com/tulios/kafkajs/blob/eae5ea42fc8ac035b0591a705b81829e3fedf8ad/src/producer/eosManager/index.js#L171-L197

I’m still quite noob on this codebase so my reasoning is probably flawed.

@ianwsperber , as you’re the main implementer of the eos code, what’s your take on this? Thanks a lot.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:38 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
Nevoncommented, Feb 9, 2022

Just as planned, now that the holidays are over, #1050 and #1172 have been merged (@tulios cleverly did not specify a year). This functionality is now available in the 1.17.0-beta.1 version. It would be extremely helpful if you could try out this version and let me know if it works as expected.

8reactions
amalcarazcommented, May 26, 2021

Any estimated date for this to be released ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

OutOfOrderSequenceException (kafka 1.0.1 API)
This exception indicates that the broker received an unexpected sequence number from the producer, which means that data may have been lost.
Read more >
apache kafka - Transactional Producer vs Just Idempotent ...
OutOfOrderSequenceException: The broker received an out of order sequence number for topic-partition topic-1 at offset -1.
Read more >
Apache Kafka idempotent producer on waitingforcode.com
The broker stores the sequence numbers sent by every producer for given topic-partition and from that it's able to say whether the message...
Read more >
Apache Kafka Idempotent Producer - Avoiding message ...
So we can end-up with messages delivered twice and out-of-order. ... When a lower sequence number is received, it is discarded.
Read more >
OutOfOrderSequenceException (clients 3.3.1 API) - javadoc.io
This exception indicates that the broker received an unexpected sequence number from the producer, which means that data may have been lost.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found