Skip to content

Fix windows OSError: [WinError 10022] An invalid argument was supplie… #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,22 @@ async def startup(self, sockets=None):
# We use this when the server is run from a Gunicorn worker.
self.servers = []
for sock in sockets:
server = await loop.create_server(
create_protocol, sock=sock, ssl=config.ssl
)
if os.name == 'nt':
Copy link
Member

@gvbgduh gvbgduh Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be nt?
There's also a handy built-in lib - https://docs.python.org/3.7/library/platform.html#platform.system for that.
So, platform.system() == "Windows" might be a bit better choice.

family = sock.family
host, port = sock.getsockname()
sock.close()
server = await loop.create_server(
create_protocol,
host=host,
port=port,
family=family,
ssl=config.ssl,
reuse_address=True
)
else:
server = await loop.create_server(
create_protocol, sock=sock, ssl=config.ssl
)
self.servers.append(server)

elif config.fd is not None:
Expand Down