Serialize websocket messages before placing them in the queue (#49582)

This commit is contained in:
J. Nick Koston 2021-04-28 05:55:18 -10:00 committed by GitHub
parent 3088f063d2
commit 11a56df2cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,11 +74,7 @@ class WebSocketHandler:
if message is None: if message is None:
break break
if not isinstance(message, str):
message = message_to_json(message)
self._logger.debug("Sending %s", message) self._logger.debug("Sending %s", message)
await self.wsock.send_str(message) await self.wsock.send_str(message)
# Clean up the peaker checker when we shut down the writer # Clean up the peaker checker when we shut down the writer
@ -94,6 +90,9 @@ class WebSocketHandler:
Async friendly. Async friendly.
""" """
if not isinstance(message, str):
message = message_to_json(message)
try: try:
self._to_write.put_nowait(message) self._to_write.put_nowait(message)
except asyncio.QueueFull: except asyncio.QueueFull: