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

Fix OSError: [WinError 87] The parameter is incorrect #1454

Merged
merged 8 commits into from
Jun 22, 2022

Conversation

euri10
Copy link
Member

@euri10 euri10 commented Apr 20, 2022

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.

Comment on lines 17 to 20
if reload:
logger.warning(
"The --reload flag should not be used in production on Windows."
)
Copy link
Member

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"?

Copy link
Member

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.

Copy link
Member

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.

@Kludex
Copy link
Member

Kludex commented May 5, 2022

@euri10 Can we pass a flag use_subprocess instead of both reload and workers? Or... Even better, can we check on asyncio_setup() function if we are running on a subprocess? I guess that's the case we want to set the SelectorEventLoop.

@Kludex Kludex added the windows label May 5, 2022
@smitchell6879
Copy link

So I am guessing this was never fixed?

@Kludex
Copy link
Member

Kludex commented Jun 7, 2022

Yep. That's correct.

@euri10 is away for some time, so anyone can take this PR, and help. Steps:

  • try to understand my comments
  • see if they are reasonable
  • reply my comments
  • change the implementation if needed
  • I'll review it again
  • merge and release

Comments about the staleness are unnecessary. Someone motivated about this issue needs to take ownership over it.

I can help on all the steps. :)

@Kludex Kludex added the waiting author Waiting for author's reply label Jun 12, 2022
@euri10
Copy link
Member Author

euri10 commented Jun 13, 2022

@euri10 Can we pass a flag use_subprocess instead of both reload and workers? Or... Even better, can we check on asyncio_setup() function if we are running on a subprocess? I guess that's the case we want to set the SelectorEventLoop.

I added a property for that, I'm not sure how to check if we are in a subprocess at running time

@smitchell6879
Copy link

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.

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.")
Copy link
Member

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.

Copy link
Member Author

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 ?

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh and f*** windows

Copy link
Member

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:

uvicorn/uvicorn/main.py

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.

Copy link
Member Author

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

@Kludex Kludex added this to the Version 0.18.0 milestone Jun 18, 2022
@Kludex Kludex mentioned this pull request Jun 18, 2022
5 tasks
def test_config_use_subprocess(reload, workers, expected):
config = Config(app=asgi_app, reload=reload, workers=workers)
config.load()
assert config.use_subprocess == expected
Copy link
Member

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 🤔

Copy link
Member Author

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 :_)

Copy link
Member Author

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

Copy link
Member

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! ♥️🙏

Copy link
Member Author

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 :)

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

🙏

@Kludex Kludex merged commit 99ead36 into encode:master Jun 22, 2022
@euri10 euri10 deleted the win87error branch June 22, 2022 08:05
Kludex pushed a commit to sephioh/uvicorn that referenced this pull request Oct 29, 2022
* 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
Kludex pushed a commit that referenced this pull request Oct 29, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting author Waiting for author's reply windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OSError occurs when workers > 1
3 participants