Skip to content

Commit

Permalink
Avoid 100% CPU usage while socket is closed (#156)
Browse files Browse the repository at this point in the history
After stop/start kafka service, kafka-python may use 100% CPU caused by
busy-retry while the socket was closed. This fix the issue by unregister
the socket if the fd is negative.

Co-authored-by: Orange Kao <orange@aiven.io>
  • Loading branch information
wbarnha and orange-kao committed Mar 9, 2024
1 parent 5bd1323 commit cda8f81
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kafka/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ def _poll(self, timeout):
self._sensors.select_time.record((end_select - start_select) * 1000000000)

for key, events in ready:
if key.fileobj.fileno() < 0:
self._selector.unregister(key.fileobj)

if key.fileobj is self._wake_r:
self._clear_wake_fd()
continue
Expand Down

0 comments on commit cda8f81

Please sign in to comment.