mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-21 21:57:49 +00:00
Merge pull request #2189 from GNS3/fix/2188
Fix broken websocket console with Python 3.11
This commit is contained in:
commit
3040e87a7d
@ -469,7 +469,18 @@ class BaseNode:
|
||||
|
||||
try:
|
||||
# keep forwarding websocket data in both direction
|
||||
await asyncio.wait([ws_forward(telnet_writer), telnet_forward(telnet_reader)], return_when=asyncio.FIRST_COMPLETED)
|
||||
if sys.version_info >= (3, 11, 0):
|
||||
# Starting with Python 3.11, passing coroutine objects to wait() directly is forbidden.
|
||||
aws = [asyncio.create_task(ws_forward(telnet_writer)), asyncio.create_task(telnet_forward(telnet_reader))]
|
||||
else:
|
||||
aws = [ws_forward(telnet_writer), telnet_forward(telnet_reader)]
|
||||
|
||||
done, pending = await asyncio.wait(aws, return_when=asyncio.FIRST_COMPLETED)
|
||||
for task in done:
|
||||
if task.exception():
|
||||
log.warning(f"Exception while forwarding WebSocket data to Telnet server {task.exception()}")
|
||||
for task in pending:
|
||||
task.cancel()
|
||||
finally:
|
||||
log.info("Client has disconnected from console WebSocket")
|
||||
if not ws.closed:
|
||||
|
@ -29,6 +29,9 @@ from gns3server.schemas.node import (
|
||||
NODE_DUPLICATE_SCHEMA
|
||||
)
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NodeHandler:
|
||||
"""
|
||||
@ -500,6 +503,8 @@ class NodeHandler:
|
||||
await ws.send_bytes(msg.data)
|
||||
elif msg.type == aiohttp.WSMsgType.ERROR:
|
||||
break
|
||||
except ConnectionResetError:
|
||||
log.info("Websocket console connection with compute disconnected")
|
||||
finally:
|
||||
if not ws.closed:
|
||||
await ws.close()
|
||||
|
Loading…
Reference in New Issue
Block a user