Skip to content

Commit

Permalink
fix aiohttp disconnect error on websockets
Browse files Browse the repository at this point in the history
aiohttp will throw if the handler doesn't return anything.

```python
14:11:35 aiohttp ERRO Missing return statement on request handler
Traceback (most recent call last):
  File "/Users/steve/conda/envs/port/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 653, in finish_response
    prepare_meth = resp.prepare
                   ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'prepare'
```

https://docs.aiohttp.org/en/stable/web_quickstart.html#websockets
  • Loading branch information
s22chan committed Oct 27, 2024
1 parent f52f6ef commit 49e9e64
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rust/perspective-python/perspective/handlers/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, **kwargs):
self._request = kwargs.pop("request")
super().__init__(**kwargs)

async def run(self) -> None:
async def run(self) -> web.WebSocketResponse:
def inner(msg):
asyncio.get_running_loop().create_task(self._ws.send_bytes(msg))

Expand All @@ -53,3 +53,4 @@ def inner(msg):

finally:
self.session.close()
return self._ws

0 comments on commit 49e9e64

Please sign in to comment.