Skip to content

Commit

Permalink
Avoid 100% CPU usage while socket is closed
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.
  • Loading branch information
orange-kao committed Jul 31, 2020
1 parent bd557da commit 09b5574
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 @@ -634,6 +634,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 09b5574

Please sign in to comment.