Catch unhandled exception in websocket_api (#42693)
Co-authored-by: springstan <46536646+springstan@users.noreply.github.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
349e4a5ac2
commit
51f847c4b8
1 changed files with 12 additions and 12 deletions
|
@ -222,20 +222,20 @@ class WebSocketHandler:
|
||||||
self._to_write.put_nowait(None)
|
self._to_write.put_nowait(None)
|
||||||
# Make sure all error messages are written before closing
|
# Make sure all error messages are written before closing
|
||||||
await self._writer_task
|
await self._writer_task
|
||||||
except asyncio.QueueFull:
|
await wsock.close()
|
||||||
|
except asyncio.QueueFull: # can be raised by put_nowait
|
||||||
self._writer_task.cancel()
|
self._writer_task.cancel()
|
||||||
|
|
||||||
await wsock.close()
|
finally:
|
||||||
|
if disconnect_warn is None:
|
||||||
|
self._logger.debug("Disconnected")
|
||||||
|
else:
|
||||||
|
self._logger.warning("Disconnected: %s", disconnect_warn)
|
||||||
|
|
||||||
if disconnect_warn is None:
|
if connection is not None:
|
||||||
self._logger.debug("Disconnected")
|
self.hass.data[DATA_CONNECTIONS] -= 1
|
||||||
else:
|
self.hass.helpers.dispatcher.async_dispatcher_send(
|
||||||
self._logger.warning("Disconnected: %s", disconnect_warn)
|
SIGNAL_WEBSOCKET_DISCONNECTED
|
||||||
|
)
|
||||||
if connection is not None:
|
|
||||||
self.hass.data[DATA_CONNECTIONS] -= 1
|
|
||||||
self.hass.helpers.dispatcher.async_dispatcher_send(
|
|
||||||
SIGNAL_WEBSOCKET_DISCONNECTED
|
|
||||||
)
|
|
||||||
|
|
||||||
return wsock
|
return wsock
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue