`chalice local` not handle websocket error 54 or it not correctly handle socket closure
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
When a Chalice project including websocket api, run it locally, it works fine except client closing the socket will trigger an error like this:
```
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 683, in process_request_thread
self.finish_request(request, client_address)
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "[masked]/venv/lib/python3.9/site-packages/chalice/local.py", line 585, in __init__
BaseHTTPRequestHandler.__init__(
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 747, in __init__
self.handle()
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/server.py", line 435, in handle
self.handle_one_request()
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/server.py", line 401, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/opt/homebrew/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
```
In my react.js client, it was correctly closed the socket by calling `mysocket.close()`
Not sure how to fix this but in my experience, we should handle this exception `ConnectionResetError` since it not triggering any error in the aws api gateway, and it is quite a common action that the client-side drop the connection.
Please leave a comment if you guys need further information 😬
Contributor guide
Research direction
Start with chalice/local.py around the BaseHTTPRequestHandler initialization at line 585 and reproduce the issue by running a websocket API locally, then closing the client socket. Done means a normal client-side close no longer produces the shown ConnectionResetError traceback, while websocket behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100