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

Allow setting port=0 to use OS-assigned port. #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alext
Copy link

@alext alext commented Jul 10, 2023

What do these changes do?

Allow using port=0 when creating a Controller to use an OS-assigned port. Using port=0 is useful for ephemeral servers (eg for tests) where a given port can't necessarily be guaranteed to be available.

Are there changes in behavior for the user?

No changes to existing behaviour (when specifying a non-zero port, or leaving it at the default).

Related issue number

Closes: #276 (this implements the changes described in the comments on that issue)

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • tox testenvs have been executed in the following environments:
    • Linux (Ubuntu 22.04): py310-nocov (test_server.py only)
  • Documentation reflects the changes
  • Add a news fragment into the NEWS.rst file

Using port=0 is useful for ephemeral servers (eg for tests) where a
given port can't necessarily be guaranteed to be available.

Setting port=0 was failing because the _trigger_server method then
attempted to connect to the server with port 0, which didn't work.

Fix this by updating the port from the server's socket before attempting
to connect.
@alext
Copy link
Author

alext commented Jul 10, 2023

Note: I've not been able to get the full test suite to run locally - it appears to hang within test_main.py. I've successfully run the test_server.py tests though...

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 this pull request may close these issues.

Connection refused when setting port to zero and inside a docker container
1 participant