Allow adb stdout to contain the port number without failing#31491
Allow adb stdout to contain the port number without failing#31491DanTup merged 4 commits intoflutter:masterfrom DanTup:cros-adb-fix
Conversation
There was a problem hiding this comment.
I'm curious why this else branch exists - at this point we've already gotten a valid hostPort. We just chose to fail if we then receive any stdout from adb?
We could instead just ignore stdout output.
There was a problem hiding this comment.
I don't know for sure but I guess we're assuming if we get some unexpected output, it's could be a failure message (some tools write to stdout) and it's better to fail and review what's happened than assume that the port was mapping ok (which could result in harder to track down connection failures later in the process).
There was a problem hiding this comment.
I don't see any mention of the stdout behavior in the adb docs. If this check is only based on observations, than updating it for new observations seem perfectly reasonable.
There was a problem hiding this comment.
Yeah, I couldn't find any docs describing this (even casually in examples), so my guess is that it was based on how it seemed to work.
I still can't get my head around why Flutter doesn't get the stdout on macOS though, specifically in this case. I did try reading the ADB source code, but it's written in a language I don't speak.
There was a problem hiding this comment.
The expected failure here is that you've specified an explicit port that's already used, so it can't be opened by adb.
|
@jonahwilliams do you have any thoughts? It seems like we are just being too strict about stdout output but maybe we are missing something. |
There was a problem hiding this comment.
I'm totally fine with this but we should phrase this as if it's by the whole team, not as if it's by one individual in the team. If someone really wants to track down who wrote it, they'll use git blame.
|
Test? |
|
I've tweaked the comment and added tests that verify the behaviour for the various combinations of input |
|
@fkorotkov just got this on the Windows bot: https://cirrus-ci.com/task/5213516968493056 I'll restart it - hopefully that doesn't stop you from being able to get logs if you need to investigate. |
|
I've rebased this as it had conflicts due to other new tests in the same file. LMK if anything else is required - this is a blocker for running Flutter on ChromeOS and being able to use DevTools from the built-in browser. |

While testing on CrOS I found some strange behaviour. When running Flutter with
--observatory-port xxxxit fails like this:The reason it fails, is that our code assumes that when we call
adb forwardthatstdoutis empty if we supplied a port but that it contains the port number if we used port=0. On ChromeOS, the port is written tostdouteven when we specify it.It seems strange that this behaves differently on CrOS, so I did some testing. And it got stranger. If I run
adb forwardfrom the terminal on macOS I see the same behaviour as CrOS - it prints the port out. However, it only does it the first time (not if it's already forwarded). I can pick any random ports and then run the forward command 10 times, and it's consistent - port printed the first time, but never after:It seems like there may be some logic to this, but what I cannot explain is why when Flutter runs
adb forwardon macOS it never sees the stdout with the port number. I added logging and it never gets a port number:Yet running the exact same command (with a new port number, since that one was now forwarded) I do see the port number:
So, this change tolerates this, by allowing stdout to be exactly the port number. It will no longer throw. This seems like a sensible change, even though I'm sad I can't figure out why macOS isn't crashing all over the place too.
FWIW, in my testing the ADB versions on both machines are: