chalice icon indicating copy to clipboard operation
chalice copied to clipboard

`chalice local` not handle websocket error 54 or it not correctly handle socket closure

Open R0uter opened this issue 2 years ago • 2 comments

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/[email protected]/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/[email protected]/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/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socketserver.py", line 747, in __init__
    self.handle()
  File "/opt/homebrew/Cellar/[email protected]/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/[email protected]/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/[email protected]/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 😬

R0uter avatar May 11 '23 07:05 R0uter

Not related to your question, but how did you manage to connect to the websocket while running on chalice local?

davidfortuoso-ti avatar May 23 '23 21:05 davidfortuoso-ti

Not related to your question, but how did you manage to connect to the websocket while running on chalice local?

U don't, u need to deploy chalice first, then local debug. The websocket service between client and chalice is up in aws.🤔

R0uter avatar May 23 '23 22:05 R0uter