feat: Add dynamic port binding to TCPSite#12167
Open
rodrigobnogueira wants to merge 8 commits intoaio-libs:masterfrom
Open
feat: Add dynamic port binding to TCPSite#12167rodrigobnogueira wants to merge 8 commits intoaio-libs:masterfrom
rodrigobnogueira wants to merge 8 commits intoaio-libs:masterfrom
Conversation
Co-authored-by: J. Nick Koston <nick+github@koston.org>
Finishes PR aio-libs#10697, replacing unused_port utility in examples and correctly tracking _bound_port against the resolved socket without mutating _port.
b396198 to
4a9bac4
Compare
d12c727 to
33ce06b
Compare
Member
|
|
dd3d778 to
ee960d7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12167 +/- ##
=======================================
Coverage 98.77% 98.78%
=======================================
Files 128 128
Lines 45321 45342 +21
Branches 2405 2407 +2
=======================================
+ Hits 44768 44789 +21
Misses 393 393
Partials 160 160
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ee960d7 to
0e1ab8f
Compare
for more information, see https://pre-commit.ci
bc1a324 to
83062e3
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
This PR continues #10697 by @twhittock-disguise, adding a
portproperty toweb.TCPSitethat returns the dynamically assigned port when the site is created withport=0.Key changes:
_bound_portto track the actual runtime port without mutating_port(addressing @webknjaz's feedback).portproperty returns_bound_portafterstart(), or the requested_portbefore that.nameproperty to useself.portso logging reflects the real bound port.examples/fake_server.pyto useport=0+site.portinstead of the race-proneunused_port()helper.docs/web_advanced.rstanddocs/web_reference.rst.test_tcpsite_ephemeral_portintests/test_web_runner.py.Are there changes in behavior for the user?
Yes. Users can now retrieve the actual bound port via
site.portafter callingawait site.start(). This is especially useful whenport=0is used for ephemeral port allocation. Previously, users had to resort to the internalsite._server.sockets[0].getsockname()[1]hack.Is it a substantial burden for the maintainers to support this?
No. This is a small, self-contained change to
TCPSitethat adds a read-only property backed by a single new slot (_bound_port). It does not change any existing public API or break backward compatibility. The maintenance cost is minimal.Related issue number
Fixes #10665
Continues #10697
Checklist
CONTRIBUTORS.txtCHANGES/folder