Opening handshake when having multiple workers and charger reconnect at once
ChaitanyaYeole02 opened this issue · comments
I received this error while I am running 10 workers and connecting 18chargers at once and disconnecting all at once.
uvicorn.run("app:central_system", host="0.0.0.0", port=9000, headers=headers, workers=10, ws_ping_interval=None,
ws_ping_timeout=None, use_colors=True, log_level='info', timeout_keep_alive=30)
I received this error during events = await receive() inside handler
SCOPE {'type': 'websocket', 'asgi': {'version': '3.0', 'spec_version': '2.3'}, 'http_version': '1.1', 'scheme': 'ws', 'server': ('127.0.0.1', 9000), 'client': ('127.0.0.1', 51368), 'root_path': '', 'path': '/ocpp_id_1', 'raw_path': b'/ocpp_id_1', 'query_string': b'', 'headers': [(b'host', b'localhost:9000'), (b'upgrade', b'websocket'), (b'connection', b'Upgrade'), (b'sec-websocket-key', b'geZ9tievYay1lw3aVfUrwA=='), (b'sec-websocket-version', b'13'), (b'sec-websocket-extensions', b'permessage-deflate; client_max_window_bits'), (b'sec-websocket-protocol', b'ocpp1.6'), (b'user-agent', b'Python/3.8 websockets/10.3')], 'subprotocols': ['ocpp1.6']}
RECEIVE <bound method WebSocketProtocol.asgi_receive of <uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol object at 0x0000020F55B87C70>>
SEND <bound method WebSocketProtocol.asgi_send of <uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol object at 0x0000020F55B87C70>>
INFO: ('127.0.0.1', 51368) - "WebSocket /ocpp_id_1" [accepted]
[asgi_send - 254] ('127.0.0.1', 51368) - "WebSocket /ocpp_id_1" [accepted]
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 225, in run_asgi
result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "C:\Users\s******5\PycharmProjects\websocket\ocpp_asgi\app.py", line 91, in __call__
await self.handler(scope, receive, send)
File "C:\Users\s******5\PycharmProjects\websocket\ocpp_asgi\app.py", line 120, in handler
event = await receive()
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 336, in asgi_receive
data = await self.recv()
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\protocol.py", line 536, in recv
await asyncio.wait(
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 382, in wait
fs = {ensure_future(f, loop=loop) for f in fs}
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 382, in <setcomp>
fs = {ensure_future(f, loop=loop) for f in fs}
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 615, in ensure_future
return _ensure_future(coro_or_future, loop=loop)
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 630, in _ensure_future
raise TypeError('An asyncio.Future, a coroutine or an awaitable '
TypeError: An asyncio.Future, a coroutine or an awaitable is required
[run_asgi - 229] Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 225, in run_asgi
result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "C:\Users\s******5\PycharmProjects\websocket\ocpp_asgi\app.py", line 91, in __call__
await self.handler(scope, receive, send)
File "C:\Users\s******5\PycharmProjects\websocket\ocpp_asgi\app.py", line 120, in handler
event = await receive()
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 336, in asgi_receive
data = await self.recv()
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\protocol.py", line 536, in recv
await asyncio.wait(
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 382, in wait
fs = {ensure_future(f, loop=loop) for f in fs}
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 382, in <setcomp>
fs = {ensure_future(f, loop=loop) for f in fs}
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 615, in ensure_future
return _ensure_future(coro_or_future, loop=loop)
File "C:\Users\s******5\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 630, in _ensure_future
raise TypeError('An asyncio.Future, a coroutine or an awaitable '
TypeError: An asyncio.Future, a coroutine or an awaitable is required
ERROR: opening handshake failed
Traceback (most recent call last):
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 163, in handler
await self.handshake(
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 597, in handshake
raise self.connection_closed_exc() # pragma: no cover
websockets.exceptions.ConnectionClosedError: no close frame received or sent
[handler - 208] opening handshake failed
Traceback (most recent call last):
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 163, in handler
await self.handshake(
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 597, in handshake
raise self.connection_closed_exc() # pragma: no cover
websockets.exceptions.ConnectionClosedError: no close frame received or sent
INFO: connection failed (500 Internal Server Error)
[handler - 225] connection failed (500 Internal Server Error)
INFO: connection closed
[handler - 260] connection closed
@villekr I have tried using try, except still I get this error, this is something related to the future or coroutine in handler.This is just my guess
try:
event = await receive()
except Exception as e:
event['type'] = ASGIWebSocketEvent.disconnect
event['code'] = 1006
I tried this, then I get a handshake error
ERROR: opening handshake failed
Traceback (most recent call last):
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 163, in handler
await self.handshake(
File "C:\Users\s******5\PycharmProjects\websocket\venv\lib\site-packages\websockets\legacy\server.py", line 597, in handshake
raise self.connection_closed_exc() # pragma: no cover
websockets.exceptions.ConnectionClosedError: no close frame received or sent
@villekr What I can figure out from this is that, when my connection is abrupted due to anything, I will get this handshake error
I'm unable to reproduce this error (under Python 3.10.2). You may refer to updated example code in https://github.com/villekr/ocpp-asgi/tree/issue/15, which runs 10 workers and 20 charging stations.