-
-
Notifications
You must be signed in to change notification settings - Fork 573
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
[FR] Support listening to an ephemeral port 0
#617
Comments
IIRC, In case you are directly using If none of that works out, I agree, we can even add this feature within core where passing |
There are two problems with this. When it tries to find a free port, it may still end up being occupied because of a race condition before detecting it, closing the socket, and reopening it in the test. The chance is quite small but this is not an elegant solution.
We also have a helper in our tests, that does exactly the same. But per my point above, I'd rather use a more elegant and robust solution.
I have a local patch that does that in like changing 2 lines (although, it probably makes sense to expose this info up the stack which would require adding a few more). Let me see if I can find time to come up with a PR. P.S. For now, I've just patched the acceptor pool in tests: https://github.com/aio-libs/aiohttp/pull/6002/files#diff-be15bec475f6c781d5d3e4413c19d0e24ccaf616b8a2495c6824fc3a16d139f5R44. |
@webknjaz Totally agreed, |
Sweet, I'll be able to replace https://github.com/aio-libs/aiohttp/blob/4fcfb8a/tests/test_proxy_functional.py#L60-L69 now :) |
@abhinavsingh oh, wait, I can't upgrade |
I think pinning automagically comes from If we remove |
Btw, no dependencies were changed in my last PR. So I am thinking why did it run into a conflict now. IIUC, Lemme know. This dep is just to satisfy type checker and as such plays no functional role. So happy to relax the requirements wherever possible. |
@abhinavsingh I can tell you right away that dropping the pin will make it possible for us to actually upgrade. As a side note, with my PyPA hat on, I really recommend using https://github.com/jazzband/pip-tools1 to keep your CI/testing/dev envs reproducible but only put lower boundaries on the direct deps you add via Footnotes
|
Oh, it didn't happen right now, I noticed it a month ago but forgot to file an issue. This is why we've pinned |
Makes sense. Let me take a look into it tomorrow sometime. I am almost in bed now (5:30am here). I thought I had it covered, alas :). Yes, there is no dependency on this library, but IIRC, we did see an exception during pip package installation if this dependency is missed. I'll recheck and update the package tomorrow. Have a good day. |
@abhinavsingh #641 should fix this. This dependency is indeed used in one place in runtime but I've checked that any version of it available on PyPI has |
Thank you for digging into it :). Looks good, merged |
Is your feature request related to a problem? Please describe.
If I pass the port
0
to proxy.py when running it programmatically via the context managerProxy
, there's no way of accessing the actual port the kernel allocates.Describe the solution you'd like
I want to run proxy.py with an ephemeral port so that each time it'd get a guaranteed unoccupied port from the OS kernel. This is useful in the context of testing where I don't want to have a hardcoded port to avoid conflicts / race conditions with other processes.
I've skimmed though the code and it seems easy to implement. If you green-light this feature, I may even send you a PR myself.
Describe alternatives you've considered
Giving up or monkey-patching stuff.
Additional context
I'm trying to use proxy.py in a test suite for a web framework.
The text was updated successfully, but these errors were encountered: