Skip to content

fix: exit cleanly on Kafka commit ILLEGAL_GENERATION#70

Merged
anaselmhamdi merged 1 commit into
mainfrom
fix/kafka-illegal-generation-exit
Apr 17, 2026
Merged

fix: exit cleanly on Kafka commit ILLEGAL_GENERATION#70
anaselmhamdi merged 1 commit into
mainfrom
fix/kafka-illegal-generation-exit

Conversation

@anaselmhamdi

Copy link
Copy Markdown
Collaborator

Summary

  • When commit fails with ILLEGAL_GENERATION or UNKNOWN_MEMBER_ID, the consumer has been evicted from the group and its partitions are now owned by someone else
  • Previously these errors were silently swallowed (commit() logged and returned), so the evicted consumer kept processing messages and duplicating writes against the new partition owner until the next rebalance
  • Now the consumer is closed gracefully and the exception is re-raised, so the runner returns ERROR, the pod exits, and Kubernetes restarts it with a fresh consumer that rejoins the group cleanly
  • Other Kafka commit errors (network, broker hiccups) keep the existing log-and-continue behavior

Context

Seen repeatedly in production under v0.3.10:

ERROR Kafka exception occurred during commit: KafkaError{code=ILLEGAL_GENERATION,val=22,str="Commit failed: Broker: Specified group generation id is not valid"}
INFO  Gracefully exiting without committing offsets due to Kafka exception

Test plan

  • uv run pytest tests/connectors/sources/kafka/ — all 27 tests pass
  • uv run ruff check && ruff format --check
  • Deploy to one pipeline, trigger a rebalance, confirm: pod exits, k8s restarts, new consumer joins group cleanly

🤖 Generated with Claude Code

When the consumer's generation ID is stale (ILLEGAL_GENERATION) or it's
no longer a member (UNKNOWN_MEMBER_ID), the commit is rejected because
the partitions have been reassigned. Continuing to process just causes
duplicate writes against the new owner. Close the consumer and raise
so the runner exits and k8s restarts with a fresh consumer that
rejoins the group cleanly. Other commit errors keep log-and-continue.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@anaselmhamdi anaselmhamdi merged commit d3a6daf into main Apr 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant