changeset 51999:997c9b2069d1

zeroconf: fix an invalid argument error on Windows The idea that pyoxidizer was triggering the problem when standing up the previous incarnation of CI for Windows was misleading- it was a Windows problem in general. See the inline bug link. Unfortunately, there's no commit referenced there, and it looks like OP closed the report himself with the suggested workaround. IOW, very modern python may not work, but it's extremely unlikely that there are any users of this extension, especially on Windows.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 07 Oct 2024 23:20:09 -0400
parents 629ecced55a6
children c76c1c948804
files hgext/zeroconf/Zeroconf.py tests/test-hgrc.t tests/test-paths.t
diffstat 3 files changed, 15 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/zeroconf/Zeroconf.py	Sat Oct 12 16:55:30 2024 -0400
+++ b/hgext/zeroconf/Zeroconf.py	Mon Oct 07 23:20:09 2024 -0400
@@ -232,6 +232,16 @@
 
 # implementation classes
 
+_SOL_IP = socket.SOL_IP
+
+if pycompat.iswindows:
+    # XXX: Not sure if there are newer versions of python where this would fail,
+    # but apparently socket.SOL_IP used to be 0, and socket.IPPROTO_IP is 0, so
+    # this would work with older versions of python.
+    #
+    # https://github.com/python/cpython/issues/101960
+    _SOL_IP = socket.IPPROTO_IP
+
 
 class DNSEntry:
     """A DNS entry"""
@@ -1419,8 +1429,8 @@
             # work as expected.
             #
             pass
-        self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_TTL, b"\xff")
-        self.socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, b"\x01")
+        self.socket.setsockopt(_SOL_IP, socket.IP_MULTICAST_TTL, b"\xff")
+        self.socket.setsockopt(_SOL_IP, socket.IP_MULTICAST_LOOP, b"\x01")
         try:
             self.socket.bind(self.group)
         except Exception:
@@ -1428,7 +1438,7 @@
             # SO_REUSEADDR and SO_REUSEPORT have been set, so ignore it
             pass
         self.socket.setsockopt(
-            socket.SOL_IP,
+            _SOL_IP,
             socket.IP_ADD_MEMBERSHIP,
             socket.inet_aton(_MDNS_ADDR) + socket.inet_aton('0.0.0.0'),
         )
@@ -1844,7 +1854,7 @@
             self.engine.notify()
             self.unregisterAllServices()
             self.socket.setsockopt(
-                socket.SOL_IP,
+                _SOL_IP,
                 socket.IP_DROP_MEMBERSHIP,
                 socket.inet_aton(_MDNS_ADDR) + socket.inet_aton('0.0.0.0'),
             )
--- a/tests/test-hgrc.t	Sat Oct 12 16:55:30 2024 -0400
+++ b/tests/test-hgrc.t	Mon Oct 07 23:20:09 2024 -0400
@@ -304,15 +304,6 @@
   config error at $TESTTMP/.hg/hgrc:3: [broken
   [255]
 
-XXX-PYOXIDIZER Pyoxidizer build have trouble with zeroconf for unclear reason,
-we accept the bad output for now as this is the last thing in the way of
-testing the pyoxidizer build.
-
-#if no-pyoxidizer-in-filesystem
   $ HGRCSKIPREPO=1 hg paths --config extensions.zeroconf=
   foo = $TESTTMP/bar
-#else
-  $ HGRCSKIPREPO=1 hg paths --config extensions.zeroconf=
-  abort: An invalid argument was supplied (known-bad-output !)
-  [255]
-#endif
+
--- a/tests/test-paths.t	Sat Oct 12 16:55:30 2024 -0400
+++ b/tests/test-paths.t	Mon Oct 07 23:20:09 2024 -0400
@@ -140,21 +140,11 @@
 
 zeroconf wraps ui.configitems(), which shouldn't crash at least:
 
-XXX-PYOXIDIZER Pyoxidizer build have trouble with zeroconf for unclear reason,
-we accept the bad output for now as this is the last thing in the way of
-testing the pyoxidizer build.
-
-#if no-pyoxidizer-in-filesystem
   $ hg paths --config extensions.zeroconf=
   dupe = $TESTTMP/b#tip
   dupe:pushurl = https://example.com/dupe
   expand = $TESTTMP/a/$SOMETHING/bar
   insecure = http://foo:***@example.com/
-#else
-  $ hg paths --config extensions.zeroconf=
-  abort: An invalid argument was supplied (known-bad-output !)
-  [255]
-#endif
 
 
   $ cd ..