Description
Change Intent
try-ports logic on dart devtools
, and its defaulting to 10
, is detrimental and cause more issues on build systems than convenience (not sure who is the target. developers who run devtools one after another and forget them in the background? do we want to foster this? I honestly tried to understand when/why it was added but there was two migrations on git where this code was moved that made history hard to follow)
Justification
This logic goes against every single other daemon behaviour. (i.e. user specify --port=8000
but daemon listen on port 8001
, or 43993
or whatever other port. See bellow).
Also, probably a security issue somewhere. (e.g. deploy to stage where port 8000 is only accessible via office vpn and 8001 is connected to the your http cache egress, and devtools decide to start on port 8001).
If the caller have logic to handle that (i.e. read the command output and attach to a different port) then it should explicitly use that --try-ports
param and be happy. (or --port=0
see bellow)
Most daemons respect port parameters. It is counter-intuitive to start a webserver at a random port and search for it. If you use the --port
command, and the port is already used, the common behaviour of most servers/daemons is to fail. I cannot think of other servers that does this by default. Specially undocumented like this.
Extra points:
- it's confusing that try-ports needs
1
to respect the value of--port
. More confusing that the sensible value zero results in dart using a random port, ignoring--port=8000
entirely. crazy. - This eccentric and non-standard behaviour is not documented on most help text/online guide/
https://docs.flutter.dev/tools/devtools/cli
/etc. Only verbose help (dart help -v <topic>
) for devtools will mention it exists! I will be honest, I didn't even know there was verbose help until I looked into a patch for this and saw the hidden param docs in the source. I expected help would have helped me. - still on help text, the hidden help for this param is missing all the edge cases (e.g.
0
means use random port; or if--port
failed because of permission like using port 80 as regular user, use random port; etc) - The entire functionality of this (using unknown ports and figuring out by parsing output) is already handled by
--port=0
, which is already mentioned on the regular help for devtools just fine. -
- having to set
--try-ports=1
to have--ports=
behave like it is described in its own help text is not mentioned though.
- having to set
Impact
More secure deployments. Saner server startup. Predictable behavior. Less silent failures on CI because server decided on a port on its own instead of failing.
Some program which already reads the output of dart devtools
and parse it to get the port would fail if also using --port
. If not using port it would not notice any change.
Mitigation
set the default port to 0 (use any port).
Users who do not care about port and would be happy with random port will not even notice the change.
Better yet, --port
could accept ranges (the implementation would be much simpler than what is there today for try-ports) and default to --port=9100-9110
Change Timeline
No response
Associated CLs
No response