Skip to content

Commit 4d8f1c4

Browse files
committed
Fix race condition in coordinator join_future handling
1 parent 57cdd46 commit 4d8f1c4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

kafka/coordinator/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,23 @@ def ensure_active_group(self):
377377
# before the pending rebalance has completed.
378378
if self.join_future is None:
379379
self.state = MemberState.REBALANCING
380-
self.join_future = self._send_join_group_request()
380+
future = self._send_join_group_request()
381+
382+
self.join_future = future # this should happen before adding callbacks
381383

382384
# handle join completion in the callback so that the
383385
# callback will be invoked even if the consumer is woken up
384386
# before finishing the rebalance
385-
self.join_future.add_callback(self._handle_join_success)
387+
future.add_callback(self._handle_join_success)
386388

387389
# we handle failures below after the request finishes.
388390
# If the join completes after having been woken up, the
389391
# exception is ignored and we will rejoin
390-
self.join_future.add_errback(self._handle_join_failure)
392+
future.add_errback(self._handle_join_failure)
393+
394+
else:
395+
future = self.join_future
391396

392-
future = self.join_future
393397
self._client.poll(future=future)
394398

395399
if future.failed():

0 commit comments

Comments
 (0)