-
Notifications
You must be signed in to change notification settings - Fork 83
Reliably find unused port to start extension backend http service on #1451
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
Reliably find unused port to start extension backend http service on #1451
Conversation
We start extension backend http server with port 0, which creates flakes in flutter web tests. Find an unused port instead. Closes: dart-lang#1450
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused - I expect binding on 0
to be more reliable, but more difficult for coordination. Picking a port ahead of time should increase the likelihood of conflict if anything, but we usually do it to make coordinating across uses of the port easier.
+1 to what @natebosch said. Can you provide more context? |
Afaik picking 0 is creating an ephemeral port by the VM, which for some reason introduces flakes in web tool tests, possibly due to races with another process. Given that the port number is assigned by the VM, I have much less control on picking one with this API, so retrying would be a shot in the dark. So changed it to picking a port that is free and retrying binding to it a few times to prevent races, the same way we do for the rest of the http servers (that removed other flakes due to races before so looks reliable). The coordination does not change - in both cases, the port number is available on |
This is what I don't understand. Binding on What step is it that fails when it does flake? |
I don't know if the VM or OS has any way to resolve a race between two processes in any of those cases. I could add retries to the previous solution to avoid races, but I prefer the current fix for several reasons:
See the parent flutter issue for details (flutter/flutter#93256). The stack trace:
|
HttpServer.bind delegates to OS to choose the port. My understanding is that it is done atomically, so no two processes can get the same port. We use it(setting port to 0, querying for it after server is set up) extensively in dart vm test suite. |
Should I file the failure as a VM bug, is there something we are doing incorrectly in setting the http server? |
I'm not familiar with http_multi_server package, perhaps that should be looked at first in regards how it uses http core |
if port number '0' is used it should bind to a ephemeral port, it is possible to get an EADDRINUSE error even with a ephemeral port specification, see doc "The port number was specified as zero in the socket address structure, but, upon attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use", it is highly unlikely that you are running into a situation where we are running out port numbers. I looked at the |
Yes, please do file a bug with the stack trace you have attached above. |
Sorry ignore that, port number 0 is not being cached, but the error message indicates port 42919 is being used and not 0 which probably means 42919 is being reused |
Filed dart-lang/sdk#47806. Will check this in in for now to unblock the flutter tests, might want to revert the fix later. |
We start extension backend http server with port 0, which creates flakes
in flutter web tests. Find an unused port instead.
Closes: #1450