Try to ensure websocket is closed when forgetting about it

Might not be necessary, but if it is then it prevents a sitation where a
websocket is still open but we've forgotten about it, so we will never
broadcast any new messages to it and the client will be practically frozen in
time until they disconnect and open a new websocket.

Also update the user's last_seen when the websocket is closed. This prevents a
user with js enabled who's actually idle being considered absent and being
rotated when their websocket accidentally closes for a few seconds.
このコミットが含まれているのは:
n9k 2022-03-09 05:15:21 +00:00
コミット 4eaf9b56f7
1個のファイルの変更6行の追加0行の削除

ファイルの表示

@ -5,6 +5,7 @@ import asyncio
from quart import current_app, websocket
from anonstream.user import see
from anonstream.websocket import websocket_outbound, websocket_inbound
from anonstream.routes.wrappers import with_user_from
@ -19,4 +20,9 @@ async def live(user):
try:
await asyncio.gather(producer, consumer)
finally:
see(user)
user['websockets'].remove(queue)
try:
await websocket.close(1000)
except RuntimeError:
pass