Skip to content

Commit dd51799

Browse files
committed
Disable allow_reuse_address when on Windows
1 parent 0322ac7 commit dd51799

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

oauth2cli/authcode.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import logging
99
import socket
10+
import sys
1011
from string import Template
1112
import threading
1213
import time
@@ -104,6 +105,16 @@ def log_message(self, format, *args):
104105

105106

106107
class _AuthCodeHttpServer(HTTPServer):
108+
def __init__(self, server_address, *args, **kwargs):
109+
_, port = server_address
110+
if port and (sys.platform == "win32" or is_wsl()):
111+
# The default allow_reuse_address is True. It works fine on non-Windows.
112+
# On Windows, it undesirably allows multiple servers listening on same port,
113+
# yet the second server would not receive any incoming request.
114+
# So, we need to turn it off.
115+
self.allow_reuse_address = False
116+
super(_AuthCodeHttpServer, self).__init__(server_address, *args, **kwargs)
117+
107118
def handle_timeout(self):
108119
# It will be triggered when no request comes in self.timeout seconds.
109120
# See https://docs.python.org/3/library/socketserver.html#socketserver.BaseServer.handle_timeout

0 commit comments

Comments
 (0)