Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Socket reconnection on retries of JoinGroup, SyncGroup, LeaveGroup #939

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion pykafka/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,16 @@ def _get_unique_req_handler(self, connection_id):
handler = RequestHandler(self._handler, conn)
handler.start()
self._req_handlers[connection_id] = handler
return self._req_handlers[connection_id]

handler = self._req_handlers[connection_id]

# Ensure that we're returning a handler with a connected connection.
# If the connection is disconnected, it will raise SocketDisconnectedError
if not handler.shared.connection.connected:
log.warn('Attempting to reconnect for connection id %s..', connection_id)
handler.shared.connection.connect(self._socket_timeout_ms)

return handler

@_check_handler
def fetch_messages(self,
Expand Down
2 changes: 1 addition & 1 deletion pykafka/managedbalancedconsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ def _update_member_assignment(self):
log.debug("Successfully rebalanced consumer '%s'", self._consumer_id)
break
except Exception as ex:
log.exception(ex)
if i == self._rebalance_max_retries - 1:
log.warning('Failed to rebalance s after %d retries.', i)
raise
log.exception(ex)
log.info('Unable to complete rebalancing. Retrying')
self._cluster.handler.sleep(i * (self._rebalance_backoff_ms / 1000))
self._raise_worker_exceptions()
Expand Down