TUN-3777: Fix /ready endpoint for classic tunnels

Classic tunnels flow was triggering an event for RegisteringTunnel for
every connection that was about to be established, and then a Connected
event for every connection established.

However, the RegistreringTunnel event had no connection ID, always
causing it to unset/disconnect the 0th connection making the /ready
endpoint report incorrect numbers for classic tunnels.
This commit is contained in:
Nuno Diegues 2021-01-19 12:20:11 +00:00
parent ffac598fab
commit 2d0b86f2e4
5 changed files with 18 additions and 9 deletions

View File

@ -135,7 +135,7 @@ func (data *uiModel) Launch(
data.edgeURL = event.URL data.edgeURL = event.URL
case connection.RegisteringTunnel: case connection.RegisteringTunnel:
if data.edgeURL == "" { if data.edgeURL == "" {
tunnelHostText.SetText("Registering tunnel...") tunnelHostText.SetText(fmt.Sprintf("Registering tunnel connection %d...", event.Index))
} }
} }
app.Draw() app.Draw()

View File

@ -99,8 +99,8 @@ func trialZoneMsg(url string) []string {
} }
} }
func (o *Observer) sendRegisteringEvent() { func (o *Observer) sendRegisteringEvent(connIndex uint8) {
o.sendEvent(Event{EventType: RegisteringTunnel}) o.sendEvent(Event{Index: connIndex, EventType: RegisteringTunnel})
} }
func (o *Observer) sendConnectedEvent(connIndex uint8, location string) { func (o *Observer) sendConnectedEvent(connIndex uint8, location string) {

View File

@ -53,13 +53,13 @@ func TestObserverEventsDontBlock(t *testing.T) {
})) }))
timeout := time.AfterFunc(5*time.Second, func() { timeout := time.AfterFunc(5*time.Second, func() {
mu.Unlock() // release the callback on timer expiration mu.Unlock() // release the callback on timer expiration
t.Fatal("observer is blocked") t.Fatal("observer is blocked")
}) })
mu.Lock() // block the callback mu.Lock() // block the callback
for i := 0; i < 2 * observerChannelBufferSize; i++ { for i := 0; i < 2*observerChannelBufferSize; i++ {
observer.sendRegisteringEvent() observer.sendRegisteringEvent(0)
} }
if pending := timeout.Stop(); pending { if pending := timeout.Stop(); pending {
// release the callback if timer hasn't expired yet // release the callback if timer hasn't expired yet

View File

@ -138,7 +138,7 @@ const (
) )
func (h *h2muxConnection) registerTunnel(ctx context.Context, credentialSetter CredentialManager, classicTunnel *ClassicTunnelConfig, registrationOptions *tunnelpogs.RegistrationOptions) error { func (h *h2muxConnection) registerTunnel(ctx context.Context, credentialSetter CredentialManager, classicTunnel *ClassicTunnelConfig, registrationOptions *tunnelpogs.RegistrationOptions) error {
h.observer.sendRegisteringEvent() h.observer.sendRegisteringEvent(registrationOptions.ConnectionID)
stream, err := h.newRPCStream(ctx, register) stream, err := h.newRPCStream(ctx, register)
if err != nil { if err != nil {

View File

@ -87,7 +87,7 @@ func TestReadinessEventHandling(t *testing.T) {
}) })
code, ready = rs.makeResponse() code, ready = rs.makeResponse()
assert.EqualValues(t, http.StatusOK, code) assert.EqualValues(t, http.StatusOK, code)
assert.EqualValues(t, 2, ready) assert.EqualValues(t, 2, ready)
// one reconnecting => still ok // one reconnecting => still ok
rs.OnTunnelEvent(connection.Event{ rs.OnTunnelEvent(connection.Event{
@ -98,6 +98,15 @@ func TestReadinessEventHandling(t *testing.T) {
assert.EqualValues(t, http.StatusOK, code) assert.EqualValues(t, http.StatusOK, code)
assert.EqualValues(t, 1, ready) assert.EqualValues(t, 1, ready)
// Regression test for TUN-3777
rs.OnTunnelEvent(connection.Event{
Index: 1,
EventType: connection.RegisteringTunnel,
})
code, ready = rs.makeResponse()
assert.NotEqualValues(t, http.StatusOK, code)
assert.Zero(t, ready)
// other disconnected => not ok // other disconnected => not ok
rs.OnTunnelEvent(connection.Event{ rs.OnTunnelEvent(connection.Event{
Index: 1, Index: 1,