fix(startup): Differentiate between None vs. 0 port #3037
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.
I'm currently developing a sanic application which should support service discovery.
In order to have a degree of freedom in choosing how to run sanic in this context, I'm in need of random ports to be chosen by the operating system.
Intentionally, at least according to the docs, this should be possible by simply setting port either to
None
or0
.Though, I stumbled upon the
mixin/startup
code which is in case of a tls start up fixing this to8443
or8000
in both occasions, since coalescing port like thisport = port or 8443 if (version == 3 or auto_tls) else 8000
will be in both cases (
0
andNone
) fallback to this term8443 if (version == 3 or auto_tls) else 8000
Since I do not want to break anything, I suggest changing this to the following behaviour:
In case of
port=None
persist the logic as isIn case of
port=0
let the OS handle choosing a port for us (which would be a random port)Feedback is very much welcome and I'm open for alternative approaches.
If we could enable this one way or the other I'd very much appreciate it.
(Thank you for this awesome framework ❤️ )