Kafka consumer stops processing messages
After migration to kafka-python 2.1.5 from 2.0.2 our kafka consumers stops processing messages for some instances (happens every 12-13 hour) for a consumer group. There also increased occurrences of group rebalancing.
I do have the same issue, been using 2.0.2 for a few years with no particular issue (only some rebalancing when there are very few messages to be read), also working fine with 2.0.6 but any release from 2.1.0 up to 2.2.2 results in no message being read ... also using group management.
Comparing the DEBUG logs the fetch-throttle-time sensor seems to be missing with releases > 2.0.6 ... just guessing this could the reason or a symptom why my consumers do not read anything ... or maybe not.
Anyway the consumer does not log anything after the following lines with 2.1.x or 2.2.x, and calls to poll() do not return any record.
2025-05-01 18:34:39,251 - DEBUG - $GMTK1 - Node bootstrap-0 connected
2025-05-01 18:34:39,257 - DEBUG - $GMTK1 - Added sensor with name bytes-fetched
2025-05-01 18:34:39,265 - DEBUG - $GMTK1 - Added sensor with name records-fetched
2025-05-01 18:34:39,273 - DEBUG - $GMTK1 - Added sensor with name fetch-latency
2025-05-01 18:34:39,279 - DEBUG - $GMTK1 - Added sensor with name records-lag
2025-05-01 18:34:39,287 - DEBUG - $GMTK1 - Added sensor with name heartbeat-latency
2025-05-01 18:34:39,295 - DEBUG - $GMTK1 - Added sensor with name join-latency
2025-05-01 18:34:39,301 - DEBUG - $GMTK1 - Added sensor with name sync-latency
2025-05-01 18:34:39,307 - DEBUG - $GMTK1 - Added sensor with name commit-latency
2025-05-01 18:34:39,315 - INFO - $GMTK1 - Updating subscribed topics to: ('oamds-mtonline',)
Are you calling consumer.poll()? Are you passing any value for timeout_ms? Can you try passing a non-zero timeout_ms value: consumer.poll(timeout_ms=1000) ?
I think the two of you probably have different issues. My guess is @berrfred is calling poll w/o a timeout_ms (based on logs). And I suspect that @ajaynegi-et may be hitting issues related to #2604
Please try again with 2.2.3 (and with a non-zero timeout_ms poll value)
no, we use this syntax for iterating over messages - for msg in self.consumer is it not the preferred approach now ?
Also, upon further debugging we have found that this issue is happening for consumer which gets 2 partitions assigned
I confirm I use a zero timeout_ms poll value and take care of scheduling the poll calls in some other way ... because I experienced some serious problems in the past (don't remember if infinite loop and/or high cpu consumption), maybe due to our very specific platform it is running on (HPE NonStop). That said, it works perfectly fine with 2.0.2 and 2.0.6.
Will give a try with latest release and a non-zero timeout_ms ... but is there any reason why a zero value becomes a problem with latest releases ?
We also ran into issues when updating from 2.0.2 to 2.1.5 or 2.2.2.
In both cases, the connection to kafka had been successfull, but nothing had been polled.
One particular observation from the logs, there had not been any Group Coordinator exchange messages anymore.
For us, the fix had been to set a non-zero timeout_ms value.
If a non-zero timeout_ms value is required for a scenario with a group coordinator, I think this should be documented in the API documentation, and marked as breaking change in the release notes.
But my guess is, this actually in an error. I noticed that with commit: https://github.com/dpkp/kafka-python/commit/36287cb4fa8ab453f75500770e0af17cfca0f816 the timeout_ms of the poll started to be forwarded to the Group-Coordinator poll (previously, this just called "poll" without parameter". This might prevent the coordinator poll from succeeding.
A non zero timeout_ms value also fixes the issue in my environment but given the past experience I would definitely feel more confident if I could keep managing externally the time interval between polls and keep a zero timeout_ms.
Do all of the non-zero timeout_ms folks mind opening a different issue? That is not the OPs issue and you've hijacked this a bit :)
@ajaynegi-et - message iteration is still preferred. Do you have any other logs or errors that are correlated with your consumers failing? Have you been able to try with 2.2.3?
Another consumer fix landed in 2.2.6 that could be related. If you have a chance to test, please let me know if it fixes.
Please re-open if you are still seeing issues with latest release.