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

@ -23,12 +23,13 @@ type multiTUN struct {
close chan struct{} close chan struct{}
closeErr chan error closeErr chan error
reads chan ioRequest reads chan ioRequest
writes chan ioRequest writes chan ioRequest
flushes chan chan error flushes chan chan error
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.
@ -64,16 +65,17 @@ type nameReply struct {
func newTUNDevices() *multiTUN { func newTUNDevices() *multiTUN {
d := &multiTUN{ d := &multiTUN{
devices: make(chan tun.Device), devices: make(chan tun.Device),
events: make(chan tun.Event), events: make(chan tun.Event),
close: make(chan struct{}), close: make(chan struct{}),
closeErr: make(chan error), closeErr: make(chan error),
reads: make(chan ioRequest), reads: make(chan ioRequest),
writes: make(chan ioRequest), writes: make(chan ioRequest),
flushes: make(chan chan error), flushes: make(chan chan error),
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