mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-26 22:00:27 +03:00
feat(telnet_server): improve error handling and connection management
- Catch OSError alongside ConnectionError in connection processing to handle more network errors - Move client_info retrieval inside try block to prevent AttributeError on failed connections - Replace bare except with specific exceptions (OSError, ConnectionError, asyncio.TimeoutError) - Improve error logging to include specific exception details and client information
This commit is contained in:
parent
e4faf673af
commit
cda5fdd94b
@ -213,7 +213,7 @@ class AsyncioTelnetServer:
|
|||||||
await self._write_intro(network_writer, echo=self._echo, binary=self._binary, naws=self._naws)
|
await self._write_intro(network_writer, echo=self._echo, binary=self._binary, naws=self._naws)
|
||||||
await connection.connected()
|
await connection.connected()
|
||||||
await self._process(network_reader, network_writer, connection)
|
await self._process(network_reader, network_writer, connection)
|
||||||
except ConnectionError:
|
except (ConnectionError, OSError):
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
network_writer.close()
|
network_writer.close()
|
||||||
# await network_writer.wait_closed() # this doesn't work in Python 3.6
|
# await network_writer.wait_closed() # this doesn't work in Python 3.6
|
||||||
@ -303,14 +303,15 @@ class AsyncioTelnetServer:
|
|||||||
|
|
||||||
# Replicate the output on all clients
|
# Replicate the output on all clients
|
||||||
for connection_key in list(self._connections.keys()):
|
for connection_key in list(self._connections.keys()):
|
||||||
client_info = connection_key.get_extra_info("socket").getpeername()
|
|
||||||
connection = self._connections[connection_key]
|
connection = self._connections[connection_key]
|
||||||
|
client_info = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
client_info = connection_key.get_extra_info("socket").getpeername()
|
||||||
connection.writer.write(data)
|
connection.writer.write(data)
|
||||||
await asyncio.wait_for(connection.writer.drain(), timeout=10)
|
await asyncio.wait_for(connection.writer.drain(), timeout=10)
|
||||||
except:
|
except (OSError, ConnectionError, asyncio.TimeoutError) as e:
|
||||||
log.debug(f"Timeout while sending data to client: {client_info}, closing and removing from connection table.")
|
log.debug(f"Error sending data to client {client_info}: {e}, closing and removing from connection table.")
|
||||||
connection.close()
|
connection.close()
|
||||||
self._connections.pop(connection_key, None)
|
self._connections.pop(connection_key, None)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user