Author Michael Rich
Recipients Michael Rich
Date 2020-06-27.04:21:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Hi, a web server can be incorrectly bound to an already in-use socket when binding a HTTPServer on windows.  The issue is discussed here:

This only happens on Windows.  In *nix the socketserver will throw an error, on Windows it will not.  However the most recently bound server will not receive the requests.

I suggest the following code (taken from stackoverflow) at the start of the server_bind method:

if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
            # Also need to change the value of allow_reuse_address (defined in http.server.HTTPServer)
            HTTPServer.allow_reuse_address = 0

I have tested this and it will throw an error upon reuse in Windows and does not change *nix behavior.


Date User Action Args
2020-06-27 04:21:05Michael Richsetrecipients: + Michael Rich
2020-06-27 04:21:05Michael Richsetmessageid: <>
2020-06-27 04:21:05Michael Richlinkissue41135 messages
2020-06-27 04:21:05Michael Richcreate