Merge branch 'fix/telnet-server-connection-race-condition-3.0' into feature/ai-copilot-bridge

This commit is contained in:
YueGuobin committed 2026-03-15 13:38:40 +08:00
commit 4f8daced17
3 files changed
+682 -6

No files matched your search

+8 -6
View File
@@ -213,7 +213,7 @@ class AsyncioTelnetServer:
await self._write_intro(network_writer, echo=self._echo, binary=self._binary, naws=self._naws)
await connection.connected()
await self._process(network_reader, network_writer, connection)
except ConnectionError:
except (ConnectionError, OSError):
async with self._lock:
network_writer.close()
# await network_writer.wait_closed() # this doesn't work in Python 3.6
@@ -224,7 +224,8 @@ class AsyncioTelnetServer:
self._current_read.cancel()
await connection.disconnected()
del self._connections[network_writer]
# Use pop() to avoid KeyError if connection was already removed
self._connections.pop(network_writer, None)
async def close(self):
for writer, connection in self._connections.items():
@@ -302,16 +303,17 @@ class AsyncioTelnetServer:
# Replicate the output on all clients
for connection_key in list(self._connections.keys()):
client_info = connection_key.get_extra_info("socket").getpeername()
connection = self._connections[connection_key]
client_info = None
try:
client_info = connection_key.get_extra_info("socket").getpeername()
connection.writer.write(data)
await asyncio.wait_for(connection.writer.drain(), timeout=10)
except:
log.debug(f"Timeout while sending data to client: {client_info}, closing and removing from connection table.")
except (OSError, ConnectionError, asyncio.TimeoutError) as e:
log.debug(f"Error sending data to client {client_info}: {e}, closing and removing from connection table.")
connection.close()
del self._connections[connection_key]
self._connections.pop(connection_key, None)
async def _read(self, cmd, buffer, location, reader):
""" Reads next op from the buffer or reader"""