]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
deal with more windows idiosyncracies
authorBob Halley <halley@dnspython.org>
Sun, 12 Jun 2022 00:07:29 +0000 (17:07 -0700)
committerBob Halley <halley@dnspython.org>
Sun, 12 Jun 2022 00:07:29 +0000 (17:07 -0700)
tests/nanonameserver.py

index 7246e112b3168f8c53358eb42bd7846a9279cc39..bc655abc2f48fdc36e4f2270c3ac03fa94a64a6f 100644 (file)
@@ -122,13 +122,15 @@ class Server(threading.Thread):
                     if self.port == 0 and self.enable_udp:
                         try:
                             self.tcp.bind((self.address, self.udp_address[1]))
-                        except OSError as e:
-                            if (
-                                e.errno == errno.EADDRINUSE
-                                and len(open_udp_sockets) < 100
-                            ):
+                        except OSError:
+                            # We can get EADDRINUSE and other errors like EPERM, so
+                            # we just remember to close the UDP socket later, try again,
+                            # and hope we get a better port.  You'd think the OS would
+                            # know better...
+                            if len(open_udp_sockets) < 100:
                                 open_udp_sockets.append(self.udp)
                                 continue
+                            # 100 tries to find a port is enough!  Give up!
                             raise
                     else:
                         self.tcp.bind((self.address, self.port))