changeset 4130:178007785be8

web/server: disable address reuse option for BaseHTTPServer on windows On windows, a socket with the SO_REUSEADDR option set is able to bind to any port, even if there's already an active socket listening on it. test-http: check server address cannot be reused.
author Patrick Mezard <pmezard@gmail.com>
date Mon, 19 Feb 2007 10:08:59 +0100
parents e817c68edfed
children 1ca664c964e0
files mercurial/hgweb/server.py tests/test-http tests/test-http.out
diffstat 3 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/server.py	Mon Feb 19 10:32:46 2007 +0100
+++ b/mercurial/hgweb/server.py	Mon Feb 19 10:08:59 2007 +0100
@@ -197,6 +197,11 @@
                 pass
 
     class MercurialHTTPServer(object, _mixin, BaseHTTPServer.HTTPServer):
+        
+        # SO_REUSEADDR has broken semantics on windows
+        if os.name == 'nt':
+            allow_reuse_address = 0
+    
         def __init__(self, *args, **kargs):
             BaseHTTPServer.HTTPServer.__init__(self, *args, **kargs)
             self.accesslog = accesslog
--- a/tests/test-http	Mon Feb 19 10:32:46 2007 +0100
+++ b/tests/test-http	Mon Feb 19 10:08:59 2007 +0100
@@ -6,6 +6,8 @@
 hg commit -A -d '0 0' -m 1
 hg --config server.uncompressed=True serve -p 20059 -d --pid-file=../hg1.pid
 hg serve -p 20060 -d --pid-file=../hg2.pid
+# Test server address cannot be reused
+hg serve -p 20060 2>&1 | sed -e 's/abort: cannot start server:.*/abort: cannot start server:/'
 cd ..
 cat hg1.pid hg2.pid >> $DAEMON_PIDS
 
--- a/tests/test-http.out	Mon Feb 19 10:32:46 2007 +0100
+++ b/tests/test-http.out	Mon Feb 19 10:08:59 2007 +0100
@@ -1,4 +1,5 @@
 adding foo
+abort: cannot start server:
 % clone via stream
 streaming all changes
 XXX files to transfer, XXX bytes of data