Skip to content

Commit

Permalink
Merge pull request #168 from davrodpin/fix-reconnect
Browse files Browse the repository at this point in the history
Execute reconnection on a goroutine
  • Loading branch information
davrodpin authored Sep 16, 2021
2 parents 24359d4 + f052df4 commit a409de2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ func (t *Tunnel) Start() error {

log.Debugf("restablishing the tunnel after disconnection: %s", t)

t.connect()
// The reconnecion must happens on a goroutine to support the scenario
// where tunnel.Stop() is called while the tunnel.connect() is getting
// executed.
//
// In an event where tunnel.reconnect receives data from any point of the
// code rather than tunnel.dial(), which is evoked by tunnel.connect()
// this code needs to be updated to make sure tunnel.connect() is not
// schedule in two goroutines at the same time.
go t.connect()
}
case err := <-t.done:
if t.client != nil {
Expand Down

0 comments on commit a409de2

Please sign in to comment.