Skip to content

Commit

Permalink
Patch WebSocketResponse.close() to prevent WARNING:asyncio:socket.sen…
Browse files Browse the repository at this point in the history
…d() raised exception.
  • Loading branch information
gbtami committed Sep 2, 2020
1 parent 9d12b50 commit 8bdae7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 8 additions & 0 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import random
import string

from aiohttp.web import WebSocketResponse

from game import MAX_PLY

try:
Expand All @@ -22,6 +24,12 @@
log = logging.getLogger(__name__)


class MyWebSocketResponse(WebSocketResponse):
@property
def closed(self):
return self._closed or self._req is None or self._req.transport is None


async def tv_game(db, app):
""" Get latest played game id """
if app["tv"] is not None:
Expand Down
5 changes: 2 additions & 3 deletions server/wsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

import aiohttp
from aiohttp import web
from aiohttp.web import WebSocketResponse
import aiohttp_session

from broadcast import lobby_broadcast
from const import STARTED
from seek import challenge, create_seek, get_seeks, Seek
from user import User
from utils import new_game, load_game, online_count
from utils import new_game, load_game, online_count, MyWebSocketResponse

log = logging.getLogger(__name__)

Expand All @@ -38,7 +37,7 @@ async def lobby_socket_handler(request):
sockets = request.app["lobbysockets"]
seeks = request.app["seeks"]

ws = WebSocketResponse(heartbeat=3.0, receive_timeout=10.0)
ws = MyWebSocketResponse(heartbeat=3.0, receive_timeout=10.0)

ws_ready = ws.can_prepare(request)
if not ws_ready.ok:
Expand Down
5 changes: 2 additions & 3 deletions server/wsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

import aiohttp
from aiohttp import web
from aiohttp.web import WebSocketResponse
import aiohttp_session

from broadcast import lobby_broadcast, round_broadcast
from const import ANALYSIS, STARTED
from fairy import WHITE, BLACK
from seek import challenge, Seek
from user import User
from utils import analysis_move, play_move, draw, new_game, load_game, tv_game, tv_game_user, online_count
from utils import analysis_move, play_move, draw, new_game, load_game, tv_game, tv_game_user, online_count, MyWebSocketResponse

log = logging.getLogger(__name__)

Expand All @@ -30,7 +29,7 @@ async def round_socket_handler(request):
games = request.app["games"]
db = request.app["db"]

ws = WebSocketResponse(heartbeat=3.0, receive_timeout=10.0)
ws = MyWebSocketResponse(heartbeat=3.0, receive_timeout=10.0)

ws_ready = ws.can_prepare(request)
if not ws_ready.ok:
Expand Down

1 comment on commit 8bdae7a

@gbtami
Copy link
Owner Author

@gbtami gbtami commented on 8bdae7a Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.