]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix Python 3.6 StreamWriter compatibility issue
authorMichał Kępień <michal@isc.org>
Fri, 11 Apr 2025 14:14:57 +0000 (09:14 -0500)
committerMichał Kępień <michal@isc.org>
Fri, 11 Apr 2025 14:14:57 +0000 (09:14 -0500)
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

bin/tests/system/isctest/asyncserver.py

index 9d1a1d3cacef86c472d196f92db70e9458a2f699..33ca5ad6911036691d7bb9b69d0be31c4000a289 100644 (file)
@@ -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