Skip to content

fix: stop the ZooKeeper Kazoo client when its channel closes - #2846

Open
mvanhorn wants to merge 1 commit into
celery:mainfrom
mvanhorn:fix/2830-zookeeper-channel-close-kazoo
Open

mvanhorn wants to merge 1 commit into
celery:mainfrom
mvanhorn:fix/2830-zookeeper-channel-close-kazoo

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Motivation

Closing a ZooKeeper channel or connection leaves the Kazoo client running, so ZooKeeper sessions and background threads keep going after the caller has already shut the channel down. A later close of the same channel also does not clean that leftover client up.

Channel never overrode close(), so the lazily created Kazoo client was never stopped or closed. Superclass close() still restored unacked messages, but self._client stayed alive.

What this changes

Channel.close() now calls the superclass close first, then stops and closes the Kazoo client and clears self._client. Nested try/finally still closes the client if stop() fails, and the handle is only cleared after close() succeeds so a later close can retry. Close does not create a client if none exists, and a second successful close does not stop it again.

Reproduction

  • pytest could not load the ZooKeeper unit tests because the amqp dependency is missing.
  • A run with the kombu Channel change reverted gave no clear result, so no test is shown to catch this bug.
  • The changed test t/unit/transport/test_zookeeper.py did not run here: the amqp module is not installed.

Fixes #2830

Channel.close() now calls the superclass close first, then stops and
closes the Kazoo client and clears self._client. Nested try/finally
still closes the client if stop() fails, and the handle is only cleared
after close() succeeds so a later close can retry. Close does not create
a client if none exists, and a second successful close does not stop it
again.

Fixes celery#2830
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.78%. Comparing base (445027e) to head (6c583b7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2846      +/-   ##
==========================================
+ Coverage   85.77%   85.78%   +0.01%     
==========================================
  Files          80       80              
  Lines       11595    11604       +9     
  Branches     1403     1404       +1     
==========================================
+ Hits         9946     9955       +9     
  Misses       1428     1428              
  Partials      221      221              

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

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.

ZooKeeper transport: closing a channel never stops its Kazoo client

1 participant