Skip to content
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

Run uvicorn with multiple workers on Windows - WinError 87 #342

Closed
marodev opened this issue Apr 4, 2019 · 38 comments · Fixed by #456
Closed

Run uvicorn with multiple workers on Windows - WinError 87 #342

marodev opened this issue Apr 4, 2019 · 38 comments · Fixed by #456

Comments

@marodev
Copy link

marodev commented Apr 4, 2019

Describe the bug
Uvicorn doesn't seem to be able to start with multiple workers.

Code snippet
Starlette Hello World

import uvicorn as uvicorn
from starlette.applications import Starlette
from starlette.responses import JSONResponse

app = Starlette(debug=True)


@app.route('/')
async def homepage(request):
    return JSONResponse({'hello': 'world'})


if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000, workers=2)

Expected behavior

Uvicorn starts and is ready to serve with multiple workers.

Environment

Windows 10
Uvicorn: 0.6.1
Python: 3.7.2
Starlette: 0.11.4

Additional context

(venv) C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37>python main.py

INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started parent process [35788]

Traceback (most recent call last):

  File "main.py", line 14, in <module>
    uvicorn.run(app, host='127.0.0.1', port=8000, workers=2)
	
  File "C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37\venv\lib\site-packages\uvicorn\main.py", line 274, in run
    supervisor.run(server.run, sockets=[socket])
	
  File "C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37\venv\lib\site-packages\uvicorn\supervisors\multiprocess.py", line 33, in run
    process.start()
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
	
AttributeError: Can't pickle local object 'request_response.<locals>.app'

(venv) C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 99, in spawn_main
    new_handle = reduction.steal_handle(parent_pid, pipe_handle)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 82, in steal_handle
    _winapi.PROCESS_DUP_HANDLE, False, source_pid)
	
OSError: [WinError 87] The parameter is incorrect

@tomchristie
Copy link
Member

You'll need to run uvicorn from the command line if you want multi-workers with windows.

@marodev
Copy link
Author

marodev commented Apr 5, 2019

@tomchristie This results in another exception.

Code snippet

main.py

from starlette.applications import Starlette
from starlette.responses import JSONResponse

app = Starlette(debug=True)


@app.route('/')
async def homepage(request):
    return JSONResponse({'hello': 'world'})

Executed command

pipenv run uvicorn main:app --workers 2

Traceback

INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started parent process [34784]
INFO: Started server process [17864]
INFO: Waiting for application startup.
INFO: Started server process [34164]
INFO: Waiting for application startup.
Process Process-2:

Traceback (most recent call last):
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
	
  File "c:\users\marodev\.virtualenvs\uvicornstarlettepipenvhelloworldpy37-kkpkok1a\lib\site-packages\uvicorn\main.py", line 303, in run
    loop.run_until_complete(self.serve(sockets=sockets))
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
	
  File "c:\users\marodev\.virtualenvs\uvicornstarlettepipenvhelloworldpy37-kkpkok1a\lib\site-packages\uvicorn\main.py", line 318, in serve
    await self.startup(sockets=sockets)
	
  File "c:\users\marodev\.virtualenvs\uvicornstarlettepipenvhelloworldpy37-kkpkok1a\lib\site-packages\uvicorn\main.py", line 340, in startup
    create_protocol, sock=socket, ssl=config.ssl
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 1397, in create_server
    server._start_serving()
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 287, in _start_serving
    sock.listen(self._backlog)
	
OSError: [WinError 10022] An invalid argument was supplied

ERROR: Task was destroyed but it is pending!

task: <Task pending coro=<LifespanOn.main() running at c:\users\marodev\.virtualenvs\uvicornstarlettepipenvhelloworldpy37-kkpkok1a\lib\site-packages\uvicorn\lifespan\on.py:43> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000001F839EB4168>()]>>

ERROR: Exception in 'lifespan' protocol

Traceback (most recent call last):
  File "c:\users\marodev\.virtualenvs\uvicornstarlettepipenvhelloworldpy37-kkpkok1a\lib\site-packages\uvicorn\lifespan\on.py", line 43, in main
    await app_instance(self.receive, self.send)
	
GeneratorExit

@tomchristie
Copy link
Member

Can any windows users confirm if this issue is reproducible?
@marodev are you still able to reproduce against the latest version?

@marodev
Copy link
Author

marodev commented Jul 1, 2019

@tomchristie still same issue. Stacktrace:

(untitled2)  C:\Users\marodev\source\repos\untitled2>pipenv run uvicorn main:app --workers 2
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started parent process [13300]
INFO: Started server process [12956]
INFO: Waiting for application startup.
INFO: Started server process [2708]
INFO: Waiting for application startup.
Process Process-2:
Traceback (most recent call last):
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\marodev\.virtualenvs\untitled2-ojqfjzqw\lib\site-packages\uvicorn\main.py", line 307, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "c:\users\marodev\.virtualenvs\untitled2-ojqfjzqw\lib\site-packages\uvicorn\main.py", line 322, in serve
    await self.startup(sockets=sockets)
  File "c:\users\marodev\.virtualenvs\untitled2-ojqfjzqw\lib\site-packages\uvicorn\main.py", line 349, in startup
    create_protocol, sock=sock, ssl=config.ssl
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 1397, in create_server
    server._start_serving()
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 287, in _start_serving
    sock.listen(self._backlog)
OSError: [WinError 10022] An invalid argument was supplied
ERROR: Task was destroyed but it is pending!
task: <Task pending coro=<LifespanOn.main() running at c:\users\marodev\.virtualenvs\untitled2-ojqfjzqw\lib\site-packages\uvicorn\lifespan\on.py:44> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000019218AE8498>()]>>
INFO: ASGI 'lifespan' protocol appears unsupported.

Uvicorn: 0.8.3
Starlette: 0.12.1
Python: 3.7.2
OS: Win 10 Enterprise

@BlackHoleFox
Copy link

I can confirm this is also happening to me, Windows 10 Pro.

@grandynguyen
Copy link

Same error here. uvicorn==0.8.6

@seanaye
Copy link

seanaye commented Aug 9, 2019

Is there a workaround for this? Gunicorn is not supported on windows at all.

  • uvicorn 0.8.6
  • python 3.7.4
  • windows server 2019

@oTree-org
Copy link

Same issue for me also.

@pgjones
Copy link
Contributor

pgjones commented Aug 15, 2019

Hi @tomchristie, I've also come across this in Hypercorn. I think pgjones/hypercorn@146e095 is a fix, but I've limited understanding and ability to test Windows systems.

@ghostzero192
Copy link

ghostzero192 commented Nov 11, 2019

i updated to uvicorn==0.10.4 and still havin this issue

import uvicorn

if __name__ == "__main__":
    uvicorn.run("main:app", host='127.0.0.1', port=8000, workers=4, access_log=False)

also tried from the command line

i'm doing something wrong?

Traceback (most recent call last):
  File "c:\Program Files\Python37\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "c:\Program Files\Python37\lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\zero\documents\packs\python\envs\asyncapis\lib\site-packages\uvicorn\supervisors\multiprocess.py", line 42, in start_subprocess
    target(**kwargs)
  File "c:\users\zero\documents\packs\python\envs\asyncapis\lib\site-packages\uvicorn\main.py", line 340, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "c:\Program Files\Python37\lib\asyncio\base_events.py", line 579, in run_until_complete
    return future.result()
  File "c:\users\zero\documents\packs\python\envs\asyncapis\lib\site-packages\uvicorn\main.py", line 357, in serve
    await self.startup(sockets=sockets)
  File "c:\users\zero\documents\packs\python\envs\asyncapis\lib\site-packages\uvicorn\main.py", line 386, in startup
    create_protocol, sock=sock, ssl=config.ssl
  File "c:\Program Files\Python37\lib\asyncio\base_events.py", line 1393, in create_server
    server._start_serving()
  File "c:\Program Files\Python37\lib\asyncio\base_events.py", line 282, in _start_serving
    sock.listen(self._backlog)
OSError: [WinError 10022] An invalid argument was supplied

@AadiMehta
Copy link

Still getting this same issue. Can somebody please help me:
(p7) C:\Users\Aaditya\Desktop\Upwork\Antonio\example>uvicorn expl:app --workers 2 �[32mINFO�[0m: Uvicorn running on �[1mhttp://127.0.0.1:8000�[0m (Press CTRL+C to quit) �[32mINFO�[0m: Started parent process [�[36m�[1m7700�[0m] �[32mINFO�[0m: Started server process [�[36m5652�[0m] �[32mINFO�[0m: Started server process [�[36m13552�[0m] Process SpawnProcess-2: �[32mINFO�[0m: Waiting for application startup. �[32mINFO�[0m: Application startup complete. Traceback (most recent call last): File "C:\Users\Aaditya\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 297, in _bootstrap self.run() File "C:\Users\Aaditya\AppData\Local\Programs\Python\Python37\Lib\multiprocessing\process.py", line 99, in run self._target(*self._args, **self._kwargs) File "c:\users\aaditya\desktop\upwork\antonio\p7\lib\site-packages\uvicorn\subprocess.py", line 73, in subprocess_started target(sockets=sockets) File "c:\users\aaditya\desktop\upwork\antonio\p7\lib\site-packages\uvicorn\main.py", line 341, in run loop.run_until_complete(self.serve(sockets=sockets)) File "C:\Users\Aaditya\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 579, in run_until_complete return future.result() File "c:\users\aaditya\desktop\upwork\antonio\p7\lib\site-packages\uvicorn\main.py", line 358, in serve await self.startup(sockets=sockets) File "c:\users\aaditya\desktop\upwork\antonio\p7\lib\site-packages\uvicorn\main.py", line 387, in startup create_protocol, sock=sock, ssl=config.ssl File "C:\Users\Aaditya\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 1393, in create_server server._start_serving() File "C:\Users\Aaditya\AppData\Local\Programs\Python\Python37\Lib\asyncio\base_events.py", line 282, in _start_serving sock.listen(self._backlog) OSError: [WinError 10022] An invalid argument was supplied

@ghostzero192
Copy link

ghostzero192 commented Dec 5, 2019

@AadiMehta
I found this workaround, setting the debug flag to True should work, but still bugs me, i dont know
why or how to fix this

if __name__ == "__main__":
    uvicorn.run("main:app", host='127.0.0.1', port=8000, workers=4, debug=True)

i'm using uvicorn 0.10.8
i posted this workaround in another issue: #484, i recomend that you follow that one too, maybe we get an answer soon, but in the meantime this seems to work

@AadiMehta
Copy link

@ghostzero192
I think with following way, we are not starting multiple workers at all.

if __name__ == "__main__":
    uvicorn.run("main:app", host='127.0.0.1', port=8000, workers=4, debug=True)

You can check in the subsequent messages, that only one worker process is spawned.
When Debug is set to False, it spits out the error properly. With debug set true, I think it only initiates one worker.

@tomchristie Can you please help us with the solution or workaround to this issue?

@AadiMehta
Copy link

@tomchristie Can you please provide an update?

@tomchristie
Copy link
Member

Duplicated on #514 too. Would you mind checking out that issue - I’ve put some pointers on my latest comment there. Thanks.

@tagashira
Copy link

tagashira commented Dec 12, 2019

Hi @tomchristie thanks for your work on this server. However this error is still present on windows. Can you please provide an update when you are able to nail down the error when launching multiple workers on Windows10. Thanks

I don't think this issue is closed. I would appreciate if you coul look into it and comment on it! many thanks!

image

@DougHoffmann
Copy link

I think its a problem with the uvloop itslef.
it seems to be run on uvloop wich dont have a implementation on windows yet.

resources i found:
MagicStack/uvloop#14

@tomchristie
Copy link
Member

Believe this to finally be fully resolved in 0.11.0

@jonatelo
Copy link

uvicorn 0.11.6
But this issue continues on Windows.
Is there a workaround for this?

@mdgilene
Copy link

mdgilene commented Aug 7, 2020

uvicorn 0.11.8 still see this issue. If this is a matter of uvloop/asncio not support lifespan on windows then --workers should just do nothing on windows or at least report an error.

@Archmonger
Copy link

Archmonger commented Jan 7, 2022

@tomchristie This issue needs to be reopened. Tested 0.16.0 and confirmed reproducible on Windows. Comments above me seem to agree.

Running uvicorn from command line uvicorn conreq.asgi:application --workers 3

Accept failed on a socket
socket: <asyncio.TransportSocket fd=824, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 834, in loop
    f = self._proactor.accept(sock)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect
Accept failed on a socket
socket: <asyncio.TransportSocket fd=856, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 834, in loop
    f = self._proactor.accept(sock)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect

@tomchristie
Copy link
Member

Anyone in @encode/maintainers with a Windows setup able to confirm if there's an action needed here?

@abersheeran
Copy link
Member

Anyone in @encode/maintainers with a Windows setup able to confirm if there's an action needed here?

In my Windows10, I got it.

➜ uvicorn example:app --workers 4
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started parent process [10248]
INFO:     Started server process [10120]
INFO:     Waiting for application startup.
INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
INFO:     Started server process [3992]
INFO:     Waiting for application startup.
INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
INFO:     Started server process [14540]
INFO:     Waiting for application startup.
INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
<socket.socket fd=736, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)> 2048
<socket.socket fd=832, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)> 2048
Accept failed on a socket
socket: <asyncio.TransportSocket fd=832, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
Traceback (most recent call last):
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 836, in loop
    f = self._proactor.accept(sock)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] 参数错误。
<socket.socket fd=792, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)> 2048
Accept failed on a socket
socket: <asyncio.TransportSocket fd=792, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
Traceback (most recent call last):
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 836, in loop
    f = self._proactor.accept(sock)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] 参数错误。
INFO:     Started server process [3872]
INFO:     Waiting for application startup.
INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
<socket.socket fd=696, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)> 2048
Accept failed on a socket
socket: <asyncio.TransportSocket fd=696, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
Traceback (most recent call last):
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 836, in loop
    f = self._proactor.accept(sock)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "C:\Users\AberS\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] 参数错误。

@TonyYounCH
Copy link

TonyYounCH commented Mar 16, 2022

Has this issue been resolved? I'm experiencing the same issue here.
(Running uvicorn 0.17.6 with CPython 3.9.7 on Windows)

Accept failed on a socket
socket: <asyncio.TransportSocket fd=3564, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0', 4010)>
Traceback (most recent call last):
  File "d:\Miniconda3\envs\dev\lib\asyncio\proactor_events.py", line 834, in loop
    f = self._proactor.accept(sock)
  File "d:\Miniconda3\envs\dev\lib\asyncio\windows_events.py", line 549, in accept
    self._register_with_iocp(listener)
  File "d:\Miniconda3\envs\dev\lib\asyncio\windows_events.py", line 718, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect

@Kludex Kludex reopened this Mar 17, 2022
@Dementiy
Copy link

The same issue with Python 3.9.10 and uvicorn 0.17.6.

@hansmellsgood
Copy link

same issue here, when increase number of workers

@padmans1
Copy link

padmans1 commented Jun 7, 2022

Im also facing the same issue with uvicorn 0.17.6
C:\PythonCode\simple_compare_python\simple_compare_python\env>uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
?[32mINFO?[0m: Uvicorn running on ?[1mhttp://0.0.0.0:8080?[0m (Press CTRL+C to quit)
?[32mINFO?[0m: Started parent process [?[36m?[1m8312?[0m]
?[32mINFO?[0m: Started server process [?[36m9276?[0m]
?[32mINFO?[0m: Waiting for application startup.
?[32mINFO?[0m: Application startup complete.
?[32mINFO?[0m: Started server process [?[36m6956?[0m]
?[32mINFO?[0m: Waiting for application startup.
?[32mINFO?[0m: Application startup complete.
Accept failed on a socket
socket: <asyncio.TransportSocket fd=328, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0', 8080)>
Traceback (most recent call last):
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 837, in loop
f = self._proactor.accept(sock)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 554, in accept
self._register_with_iocp(listener)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 723, in _register_with_iocp
_overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect
?[32mINFO?[0m: Started server process [?[36m3028?[0m]
?[32mINFO?[0m: Waiting for application startup.
?[32mINFO?[0m: Application startup complete.
Accept failed on a socket
socket: <asyncio.TransportSocket fd=1096, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0',
8080)>
Traceback (most recent call last):
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 837, in loop
f = self._proactor.accept(sock)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 554, in accept
self._register_with_iocp(listener)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 723, in _register_with_iocp
_overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect
?[32mINFO?[0m: Started server process [?[36m2952?[0m]
?[32mINFO?[0m: Waiting for application startup.
?[32mINFO?[0m: Application startup complete.
Accept failed on a socket
socket: <asyncio.TransportSocket fd=392, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0', 8080)>
Traceback (most recent call last):
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 837, in loop
f = self._proactor.accept(sock)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 554, in accept
self._register_with_iocp(listener)
File "C:\Users\wafuser\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 723, in _register_with_iocp
_overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect

@reggiepy
Copy link

reggiepy commented Jun 9, 2022

It turns out that everyone has the same problem. I temporarily blocked this problem by changing the number of workers running on Windows to 1. Because it will eventually run on linux, windows is only for development. But I also hope to solve this problem

@obrua
Copy link

obrua commented Jun 13, 2022

same problem

@gudipudipradeep
Copy link

gudipudipradeep commented Jun 14, 2022

Getting same issue. Please can you help on this @pgjones @tomchristie .it will help for all people.

@pgjones
Copy link
Contributor

pgjones commented Jun 14, 2022

Does this error also occur if you use Hypercorn with a number of workers?

@bbeattie-phxlabs
Copy link

bbeattie-phxlabs commented Jun 14, 2022

Does this error also occur if you use Hypercorn with a number of workers?

No, it doesn't. See #342 (comment).

@Archmonger
Copy link

Archmonger commented Jun 14, 2022

I believe the issue is related to the Python sockets lib on Windows. Windows effectively deadlocks a port during Python's initial socket configuration. So if you have multiple python threads or interpreters attempting to start listening to a socket at once, you'll get a WinError.

The consensus seems to be to use sleep between each socket listener setup. This can also be used in conjunction with some sort of retry logic that catches WinError

@Cacsjep
Copy link

Cacsjep commented Jun 20, 2022

same issue here

@Tomilla
Copy link

Tomilla commented Jul 25, 2022

same problem

@Kludex
Copy link
Sponsor Member

Kludex commented Jul 25, 2022

Does this still happens on uvicorn 0.18.2? #1454 was merged some time ago.

@satish678
Copy link

Upgrading Uvicorn to "0.18.1" solved for me!

@Kludex
Copy link
Sponsor Member

Kludex commented Jul 29, 2022

Thanks @satish678 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.