Skip to content

Commit e92d1c1

Browse files
wbarnhaorange-kao
authored andcommitted
Avoid 100% CPU usage while socket is closed (dpkp#156)
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 <[email protected]>
1 parent ec4d377 commit e92d1c1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kafka/client_async.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ def _poll(self, timeout):
637637
self._sensors.select_time.record((end_select - start_select) * 1000000000)
638638

639639
for key, events in ready:
640+
if key.fileobj.fileno() < 0:
641+
self._selector.unregister(key.fileobj)
642+
640643
if key.fileobj is self._wake_r:
641644
self._clear_wake_fd()
642645
continue

0 commit comments

Comments
 (0)