Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
regen client id during repair
Browse files Browse the repository at this point in the history
To by-pass issues where a tunnel was left in a bad state and is not
properly deregistered, regenerate the client id as part of the repair
flow. Issue #40 directly reports this state, where the tunnel died
during connect. The internal (part of cloudflared) retry mechanism
failed and terminated the controller tunnel instance.  A retry with the
same ClientID would continue to produce the same failure until the
original tunnel was deregistered cleanly; renegerating the ClientID
allows for faster recovery.
  • Loading branch information
Matt Alberts committed Oct 1, 2018
1 parent 9c4add0 commit ffcb94c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/tunnel/argo.go
Expand Up @@ -86,7 +86,7 @@ func NewArgoTunnel(route Route, log *logrus.Logger, options ...Option) (Tunnel,
Retries: opts.Retries,
HeartbeatInterval: opts.HeartbeatInterval,
MaxHeartbeats: opts.HeartbeatCount,
ClientID: utilrand.String(16),
ClientID: utilrand.String(32),
BuildInfo: origin.GetBuildInfo(),
ReportedVersion: route.Version,
LBPool: opts.LbPool,
Expand All @@ -105,7 +105,7 @@ func NewArgoTunnel(route Route, log *logrus.Logger, options ...Option) (Tunnel,
}

t := ArgoTunnel{
id: utilrand.String(8),
id: utilrand.String(16),
origin: source,
route: route,
options: opts,
Expand Down Expand Up @@ -195,7 +195,7 @@ func (t *ArgoTunnel) CheckStatus() error {
func launchFunc(a *ArgoTunnel) func() {
errCh := a.errCh
stopCh := a.stopCh
route := a.tunnelConfig
tunnelConfig := a.tunnelConfig
return func() {
// panic-recover - trigger tunnel repair machanism
// The call to origin.StartTunnelDaemon has been observed to panic.
Expand All @@ -206,7 +206,7 @@ func launchFunc(a *ArgoTunnel) func() {
errCh <- e
}
}()
errCh <- origin.StartTunnelDaemon(route, stopCh, make(chan struct{}))
errCh <- origin.StartTunnelDaemon(tunnelConfig, stopCh, make(chan struct{}))
}
}

Expand Down Expand Up @@ -269,6 +269,7 @@ func repairFunc(a *ArgoTunnel) func() {
}

close(t.stopCh)
t.tunnelConfig.ClientID = utilrand.String(32)
t.stopCh = make(chan struct{})
go launchFunc(t)()
}()
Expand Down

0 comments on commit ffcb94c

Please sign in to comment.