From 09b5574831bd59afa86ee520e4b2896d03553ca4 Mon Sep 17 00:00:00 2001 From: Orange Kao Date: Thu, 23 Jul 2020 03:00:39 +0000 Subject: [PATCH] Avoid 100% CPU usage while socket is closed 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. --- kafka/client_async.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kafka/client_async.py b/kafka/client_async.py index caa88cf5e..5731a4617 100644 --- a/kafka/client_async.py +++ b/kafka/client_async.py @@ -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