@@ -242,7 +242,7 @@ def ensure_coordinator_ready(self):
242
242
"""Block until the coordinator for this group is known
243
243
(and we have an active connection -- java client uses unsent queue).
244
244
"""
245
- with self ._lock :
245
+ with self ._client . _lock , self . _lock :
246
246
while self .coordinator_unknown ():
247
247
248
248
# Prior to 0.8.2 there was no group coordinator
@@ -345,7 +345,7 @@ def _handle_join_failure(self, _):
345
345
346
346
def ensure_active_group (self ):
347
347
"""Ensure that the group is active (i.e. joined and synced)"""
348
- with self ._lock :
348
+ with self ._client . _lock , self . _lock :
349
349
if self ._heartbeat_thread is None :
350
350
self ._start_heartbeat_thread ()
351
351
@@ -763,7 +763,7 @@ def close(self):
763
763
764
764
def maybe_leave_group (self ):
765
765
"""Leave the current group and reset local generation/memberId."""
766
- with self ._lock :
766
+ with self ._client . _lock , self . _lock :
767
767
if (not self .coordinator_unknown ()
768
768
and self .state is not MemberState .UNJOINED
769
769
and self ._generation is not Generation .NO_GENERATION ):
@@ -946,6 +946,15 @@ def run(self):
946
946
log .debug ('Heartbeat thread closed' )
947
947
948
948
def _run_once (self ):
949
+ with self .coordinator ._client ._lock , self .coordinator ._lock :
950
+ if self .enabled and self .coordinator .state is MemberState .STABLE :
951
+ # TODO: When consumer.wakeup() is implemented, we need to
952
+ # disable here to prevent propagating an exception to this
953
+ # heartbeat thread
954
+ # must get client._lock, or maybe deadlock at heartbeat
955
+ # failure callbak in consumer poll
956
+ self .coordinator ._client .poll (timeout_ms = 0 )
957
+
949
958
with self .coordinator ._lock :
950
959
if not self .enabled :
951
960
log .debug ('Heartbeat disabled. Waiting' )
@@ -961,11 +970,6 @@ def _run_once(self):
961
970
self .disable ()
962
971
return
963
972
964
- # TODO: When consumer.wakeup() is implemented, we need to
965
- # disable here to prevent propagating an exception to this
966
- # heartbeat thread
967
- self .coordinator ._client .poll (timeout_ms = 0 )
968
-
969
973
if self .coordinator .coordinator_unknown ():
970
974
future = self .coordinator .lookup_coordinator ()
971
975
if not future .is_done or future .failed ():
0 commit comments