mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Fix Core deadlock by ensuring only one ZHA log queue handler thread is running at a time (#142568)
Ensure only one log queue handler is running at a time
This commit is contained in:
parent
528ca49368
commit
271a4ba7c8
@ -514,6 +514,7 @@ class ZHAGatewayProxy(EventBase):
|
||||
self._log_queue_handler.listener = logging.handlers.QueueListener(
|
||||
log_simple_queue, log_relay_handler
|
||||
)
|
||||
self._log_queue_handler_count: int = 0
|
||||
|
||||
self._unsubs: list[Callable[[], None]] = []
|
||||
self._unsubs.append(self.gateway.on_all_events(self._handle_event_protocol))
|
||||
@ -747,7 +748,10 @@ class ZHAGatewayProxy(EventBase):
|
||||
if filterer:
|
||||
self._log_queue_handler.addFilter(filterer)
|
||||
|
||||
if self._log_queue_handler.listener:
|
||||
# Only start a new log queue handler if the old one is no longer running
|
||||
self._log_queue_handler_count += 1
|
||||
|
||||
if self._log_queue_handler.listener and self._log_queue_handler_count == 1:
|
||||
self._log_queue_handler.listener.start()
|
||||
|
||||
for logger_name in DEBUG_RELAY_LOGGERS:
|
||||
@ -763,7 +767,10 @@ class ZHAGatewayProxy(EventBase):
|
||||
for logger_name in DEBUG_RELAY_LOGGERS:
|
||||
logging.getLogger(logger_name).removeHandler(self._log_queue_handler)
|
||||
|
||||
if self._log_queue_handler.listener:
|
||||
# Only stop the log queue handler if nothing else is using it
|
||||
self._log_queue_handler_count -= 1
|
||||
|
||||
if self._log_queue_handler.listener and self._log_queue_handler_count == 0:
|
||||
self._log_queue_handler.listener.stop()
|
||||
|
||||
if filterer:
|
||||
|
Loading…
x
Reference in New Issue
Block a user