I'm using:
- Python: 3.12
- websockets: 12.0
When using the threading implementation like in this code:
importhttpfromwebsockets.sync.serverimportserve, ServerConnection, Request, Responsefromwebsockets.http11importdatastructuresdefhealth_check(websocket: ServerConnection, request: Request):
ifrequest.path=="/healthz":
returnResponse(http.HTTPStatus.OK, "OK", datastructures.Headers([]), b"OK")
else:
returnNonedefecho(websocket):
formessageinwebsocket:
websocket.send(message)
defmain():
withserve(echo, "localhost", 8765, process_request=health_check) asserver:
server.serve_forever()
main()
Any call to the /healthz endpoint works but raise a ConnectionCloseError:
connection handler failed
Traceback (most recent call last):
File "/home/flowrey/Code/poc/venv/lib64/python3.12/site-packages/websockets/sync/server.py", line 499, in conn_handler
handler(connection)
File "/home/flowrey/Code/poc/server.py", line 13, in echo
for message in websocket:
File "/home/flowrey/Code/poc/venv/lib64/python3.12/site-packages/websockets/sync/connection.py", line 162, in __iter__
yield self.recv()
^^^^^^^^^^^
File "/home/flowrey/Code/poc/venv/lib64/python3.12/site-packages/websockets/sync/connection.py", line 201, in recv
raise self.protocol.close_exc from self.recv_events_exc
websockets.exceptions.ConnectionClosedError: no close frame received or sent
I'm using:
When using the threading implementation like in this code:
Any call to the /healthz endpoint works but raise a
ConnectionCloseError: