Skip to content

Commit

Permalink
Barricade: Fix closed websockets not being cleaned up (#689)
Browse files Browse the repository at this point in the history
* Fix dangling barricade websockets
* Fix error handling responses
  • Loading branch information
timraay authored Sep 19, 2024
1 parent df7aa1c commit 7e4ff09
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rconweb/api/barricade.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ def __init__(self, *args, **kwargs):
self._last_seen_session = datetime.utcnow()
self._scan_players_task = None

async def websocket_connect(self, *args, **kwargs):
await super().websocket_connect(*args, **kwargs)
async def connect(self):
logger.info("Accepted connection with Barricade client")

await self.accept()

if self._scan_players_task and not self._scan_players_task.done():
self._scan_players_task.cancel()
self._scan_players_task = asyncio.create_task(self._scan_players_loop())

async def websocket_disconnect(self, message):
await super().websocket_disconnect(message)
async def disconnect(self, code):
logger.info("Closed connection with Barricade client")

if self._scan_players_task and not self._scan_players_task.done():
Expand Down Expand Up @@ -168,7 +168,7 @@ async def send_request(

try:
# Wait for response
response: ResponseBody = await asyncio.wait_for(fut, timeout=10)
response: dict | None = await asyncio.wait_for(fut, timeout=10)
except asyncio.TimeoutError:
logger.error("Barricade did not respond in time to request: %r", request)
raise
Expand All @@ -185,7 +185,7 @@ async def send_request(
if request.id in self._waiters:
del self._waiters[request.id]

return response.response
return response

async def handle_request(self, request: RequestBody):
if request.id in self._processing:
Expand Down

0 comments on commit 7e4ff09

Please sign in to comment.