Skip to content

Track unacked Kafka messages per QoS instance - #2680

Merged
auvipy merged 3 commits into
celery:mainfrom
kratos0718:fix-confluentkafka-qos-per-channel
Sep 30, 2026
Merged

auvipy merged 3 commits into
celery:mainfrom
kratos0718:fix-confluentkafka-qos-per-channel

Conversation

@kratos0718

Copy link
Copy Markdown
Contributor

QoS._not_yet_acked in the confluentkafka transport is a class attribute, so every channel on every connection shares one dict. can_consume() and can_consume_max_estimate() compare that shared count against the channel's own prefetch_count, which means unacked messages on one channel can stop an unrelated channel from receiving anything.

I reproduced this against a local Kafka broker (apache/kafka 3.8) with two connections, each consuming its own topic with prefetch_count=1. Once connection A held one unacked message, connection B never got its message delivered. With this change both are delivered.

The fix moves the dict into QoS.__init__, the same per-instance scoping used for the SQS and Azure Storage Queues caches in #2676 and #2679. There were no unit tests for this transport yet, so I added t/unit/transport/test_confluentkafka.py with a test that fails on main and one covering ack. The unit suite and t/integration/test_kafka.py (36 passed, 1 skipped) pass locally.

QoS._not_yet_acked was a class attribute, so every channel on every
connection shared one dict. can_consume() compared that global count
against each channel's own prefetch_count, which let one channel's
unacked messages stop an unrelated channel from receiving anything.

Initialise the dict in QoS.__init__ so each channel counts only its
own deliveries.
@auvipy
auvipy self-requested a review September 27, 2026 10:52
@auvipy auvipy added this to the 5.7.0 milestone Sep 27, 2026
@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.02%. Comparing base (21d4533) to head (260a054).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
+ Coverage   84.35%   85.02%   +0.66%     
==========================================
  Files          80       80              
  Lines       11315    11317       +2     
  Branches     1354     1354              
==========================================
+ Hits         9545     9622      +77     
+ Misses       1552     1475      -77     
- Partials      218      220       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy
auvipy merged commit e61cc04 into celery:main Sep 30, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants