mirror of
https://gitlab.isc.org/isc-projects/bind9.git
synced 2025-04-18 09:44:09 +03:00
Fix Python 3.6 StreamWriter compatibility issue
The StreamWriter.wait_closed() method was introduced in Python 3.7, so attempting to use it with Python 3.6 raises an exception. This has not been noticed before because awaiting StreamWriter.wait_closed() is the last action taken for each TCP connection and unhandled exceptions were not causing the scripts based on AsyncServer to exit prematurely until the previous commit. As per Python documentation [1], awaiting StreamWriter.wait_closed() after calling StreamWriter.close() is recommended, but not mandatory, so try to use it if it is available, without taking any fallback action in case it isn't. [1] https://docs.python.org/3.13/library/asyncio-stream.html#asyncio.StreamWriter.close
This commit is contained in:
parent
ec4c92d9d5
commit
715bd1b667
@ -580,7 +580,12 @@ class AsyncDnsServer(AsyncServer):
|
||||
|
||||
logging.debug("Closing TCP connection from %s", peer)
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
try:
|
||||
# Python >= 3.7
|
||||
await writer.wait_closed()
|
||||
except AttributeError:
|
||||
# Python < 3.7
|
||||
pass
|
||||
|
||||
async def _read_tcp_query(
|
||||
self, reader: asyncio.StreamReader, peer: Peer
|
||||
|
Loading…
x
Reference in New Issue
Block a user