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:
SigmaPic 2020-11-03 10:35:45 +01:00 committed by GitHub
parent 349e4a5ac2
commit 51f847c4b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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