-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Fix OSError: [WinError 87] The parameter is incorrect #1454
Conversation
uvicorn/loops/asyncio.py
Outdated
if reload: | ||
logger.warning( | ||
"The --reload flag should not be used in production on Windows." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably missing something. But why do we have this warning here? 🤔 Why is it assuming this place is "windows production"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I'm missing anything... I think this warning is just wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally understand why this warning is here! It's because of this comment: #1220 (comment)
It has the wrong assumption, tho! It's not because we reach this code that it's running in production.
@euri10 Can we pass a flag |
So I am guessing this was never fixed? |
Yep. That's correct. @euri10 is away for some time, so anyone can take this PR, and help. Steps:
Comments about the staleness are unnecessary. Someone motivated about this issue needs to take ownership over it. I can help on all the steps. :) |
I added a property for that, I'm not sure how to check if we are in a subprocess at running time |
Didn't mean to offend about the efforts of this pull request. I was working on it and had a solution that wasn't liked. So I assumed those that ended my pull request had a better idea of what they wanted and I just wanted to know if there was progress as for now I am running my version. |
uvicorn/loops/asyncio.py
Outdated
def asyncio_setup(reload: bool = False) -> None: # pragma: no cover | ||
if sys.version_info >= (3, 8) and sys.platform == "win32" and reload: | ||
def asyncio_setup(use_subprocess: bool = False) -> None: # pragma: no cover | ||
if sys.version_info >= (3, 8) and sys.platform == "win32" and use_subprocess: | ||
logger.warning("The --reload flag should not be used in production on Windows.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is wrong now, because we can reach this line with the --workers
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep indeed, so the use_subprocess flag is cool on the surface but does not allow to discriminate between workers usage and reload usage so I think I'm gonna revert to having both in the signature despite your comment here (#1454 (comment)), what you think ? or you get an idea as to detect at running time the fact we're in a subprocess ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that the warning itself doesn't make sense to me. If uvicorn is running under --reload
and we show the warning, it's not needed, because it's not in production anyway... How do we even know that is being used in production?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let's dig why we put this in the first place, cant remember
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was introduced in #1257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we just want to add a warning message because we want to be sure users don't use reload in production, that should be in the main.py, not on the loop setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so let's keep use_subprocess and remove the warning ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh and f*** windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so let's keep use_subprocess and remove the warning ?
Yes 👍
If we still want the warning in the future, we can add it before those lines:
Lines 552 to 557 in b1a4582
if config.should_reload: | |
sock = config.bind_socket() | |
ChangeReload(config, target=server.run, sockets=[sock]).run() | |
elif config.workers > 1: | |
sock = config.bind_socket() | |
Multiprocess(config, target=server.run, sockets=[sock]).run() |
I think the warning is acceptable, as we want to be sure the user doesn't make the mistake of running --reload
in production. But that's for another PR/discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be good for another round of review @Kludex
def test_config_use_subprocess(reload, workers, expected): | ||
config = Config(app=asgi_app, reload=reload, workers=workers) | ||
config.load() | ||
assert config.use_subprocess == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_process
doesn't exist anymore on this branch. I was fine with it tho 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I reverted too much, goinmg to do that tomorrow sorry :_)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixed up things etc... tired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! Have a good evening man!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok should be ok now @Kludex , apologies for the confusion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
* Fix OSError: [WinError 87] The parameter is incorrect * Added use_subprocess to be more generic * Black * Revert "Added use_subprocess to be more generic" This reverts commit d1b5f83 * Removed reload warning * Min diff, not sure where this came from * Min diff 2 * Redo use_subprocess
* Fix OSError: [WinError 87] The parameter is incorrect * Added use_subprocess to be more generic * Black * Revert "Added use_subprocess to be more generic" This reverts commit d1b5f83 * Removed reload warning * Min diff, not sure where this came from * Min diff 2 * Redo use_subprocess
Fixes #1317
That PR fixes the iocp error raised when workers > 1 by forcing the loop in windows the same way we do when reload is used.
I think that's the right fix, cant think of another option since we default to the iocp loop and it seems to clash with multiple processes.