gitpod icon indicating copy to clipboard operation
gitpod copied to clipboard

[cli] Await port/service expose

Open randomir opened this issue 3 years ago • 6 comments

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: image

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:

  1. introduces unwanted delay
  2. no upper bound on t_delay

Additional context

Using enterprise self-hosting version (GP 0.9.x).

randomir avatar Mar 21 '22 18:03 randomir

Hey @randomir, gp await-port should work. Do you have an example repo where we can reproduce your issue?

axonasif avatar Mar 22 '22 16:03 axonasif

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.

randomir avatar Mar 23 '22 21:03 randomir

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:

randomir avatar Apr 28 '22 18:04 randomir

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 :)

csweichel avatar Apr 28 '22 19:04 csweichel

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..

randomir avatar Apr 28 '22 19:04 randomir

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.

stale[bot] avatar Sep 21 '22 02:09 stale[bot]