Skip to content

Handle lookup_coordinator send failures #1279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions kafka/coordinator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,17 @@ def _reset_find_coordinator_future(self, result):
self._find_coordinator_future = None

def lookup_coordinator(self):
if self._find_coordinator_future is None:
self._find_coordinator_future = self._send_group_coordinator_request()

self._find_coordinator_future.add_both(self._reset_find_coordinator_future)
return self._find_coordinator_future
if self._find_coordinator_future is not None:
return self._find_coordinator_future

# If there is an error sending the group coordinator request
# then _reset_find_coordinator_future will immediately fire and
# set _find_coordinator_future = None
# To avoid returning None, we capture the future in a local variable
self._find_coordinator_future = self._send_group_coordinator_request()
future = self._find_coordinator_future
self._find_coordinator_future.add_both(self._reset_find_coordinator_future)
return future

def need_rejoin(self):
"""Check whether the group should be rejoined (e.g. if metadata changes)
Expand Down
8 changes: 8 additions & 0 deletions test/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,11 @@ def test_heartbeat(patched_coord):
patched_coord.heartbeat_task()
assert patched_coord._client.schedule.call_count == 1
assert patched_coord.heartbeat_task._handle_heartbeat_failure.call_count == 1


def test_lookup_coordinator_failure(mocker, coordinator):

mocker.patch.object(coordinator, '_send_group_coordinator_request',
return_value=Future().failure(Exception('foobar')))
future = coordinator.lookup_coordinator()
assert future.failed()