[cli] Await port/service expose
The problem
How to make sure service/port is exposed before accessing it from browser/simple-browser.
Consider something like this:
$ port=8000
$ python -m http.server $port & gp await-port $port && gp preview $(gp url $port)
In roughly one out of three runs, this fails with:

The proposal
We need a way to sync on port exposed. Something like gp await-port, but for exposed (proxied) ports/services.
For example:
$ python -m http.server $port & gp await-port $port --external && gp preview $(gp url $port)
(note the --external flag)
Considered alternative
Naive sleep(t_delay).
Problems with this approach:
- introduces unwanted delay
- no upper bound on
t_delay
Additional context
Using enterprise self-hosting version (GP 0.9.x).
Hey @randomir, gp await-port should work. Do you have an example repo where we can reproduce your issue?
Hey @axonasif, I checked the source of gp await-port before opening this issue, and saw it's simply checking /proc/net/tcp for <port> to be in listen state (and then pausing for 2s even if port is opened!)
After a port is opened on localhost, it has to be exposed by ws-proxy, and that takes some time, right?
Are you saying the upper bound for port expose via ws-proxy is 2 seconds?
FYI, I wasn't able to verify this issue on gitpod.io, as login via GH was broken at the time of filing. I tried reproducing it on gitpod.io today and was not able to. I can still reproduce it on our self-hosted install.
Let me rephrase my question: why 2 seconds in L50 of the await-port?
https://github.com/gitpod-io/gitpod/blob/bd3ba7cdecf78efb2e36d1665e3dc692460b0a33/components/gitpod-cli/cmd/await-port.go#L50
I would like to get to the bottom of why the difference in behavior on our self-hosted version (based on gitpod 0.9 / f496a745a08e9b8a2be23d8c0b5a326af09b69bc) and on gitpod.io?
A quick way to reproduce the problem described above (with high probability on our install) is:
$ test() { python -m http.server $1 & gp await-port $1 && gp preview $(gp url $1); }
$ test 8000
$ test 8001
$ test 8002
...
I wanted to direct this question to the author of the await-port.go, but git blame is obfuscated during gitpod open-sourcing, and changes hidden behind the "Initial commit". But if I were to take a wild guess, I'd say @geropl, @jankeromnes or @csweichel can answer this.. :wink:
The await-port code is very old. When it was written the port exposure did take some time because of DNS and the use Kubernetes services. None of those things plays a role anymore, we simply haven't come 'round to updating the await-port command :)
Ok, cool, thanks for the super quick answer.
Is there something we can do (I'm guessing on the infra side) on our self-hosted install (GKE, gitpod 0.9), to ensure the port is exposed within some <insert-upper-bound>? Currently, not even those 2 seconds from the await-port are always sufficient..
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.