cmd/tailscale: wait for previous tunnel(s) to close before establishing new

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/3/head
Elias Naur 5 years ago
parent e77dcd9933
commit b297135f2a

@ -29,6 +29,7 @@ type multiTUN struct {
mtus chan chan mtuReply mtus chan chan mtuReply
names chan chan nameReply names chan chan nameReply
shutdowns chan struct{} shutdowns chan struct{}
shutdownDone chan struct{}
} }
// tunDevice wraps and drives a single run.Device. // tunDevice wraps and drives a single run.Device.
@ -74,6 +75,7 @@ func newTUNDevices() *multiTUN {
mtus: make(chan chan mtuReply), mtus: make(chan chan mtuReply),
names: make(chan chan nameReply), names: make(chan chan nameReply),
shutdowns: make(chan struct{}), shutdowns: make(chan struct{}),
shutdownDone: make(chan struct{}),
} }
go d.run() go d.run()
return d return d
@ -112,6 +114,7 @@ func (d *multiTUN) run() {
<-dev.readDone <-dev.readDone
} }
devices = nil devices = nil
d.shutdownDone <- struct{}{}
case <-d.close: case <-d.close:
var derr error var derr error
for _, dev := range devices { for _, dev := range devices {
@ -279,6 +282,7 @@ func (d *multiTUN) Events() chan tun.Event {
func (d *multiTUN) Shutdown() { func (d *multiTUN) Shutdown() {
d.shutdowns <- struct{}{} d.shutdowns <- struct{}{}
<-d.shutdownDone
} }
func (d *multiTUN) Close() error { func (d *multiTUN) Close() error {

Loading…
Cancel
Save