diff --git a/homeassistant/components/logbook/websocket_api.py b/homeassistant/components/logbook/websocket_api.py index 04b288d523b..dac0da83c36 100644 --- a/homeassistant/components/logbook/websocket_api.py +++ b/homeassistant/components/logbook/websocket_api.py @@ -392,6 +392,10 @@ async def ws_event_stream( force_send=True, ) + if msg_id not in connection.subscriptions: + # Unsubscribe happened while sending historical events + return + live_stream.task = asyncio.create_task( _async_events_consumer( subscriptions_setup_complete_time, @@ -402,10 +406,6 @@ async def ws_event_stream( ) ) - if msg_id not in connection.subscriptions: - # Unsubscribe happened while sending historical events - return - live_stream.wait_sync_task = asyncio.create_task( get_instance(hass).async_block_till_done() )