Fixed tunnel race conditions. (#1094)
This commit is contained in:
parent
59fccb82ec
commit
78aed5beed
@ -201,15 +201,15 @@ func (t *tun) announce(channel, session string, link *link) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// manage monitors outbound links and attempts to reconnect to the failed ones
|
// manage monitors outbound links and attempts to reconnect to the failed ones
|
||||||
func (t *tun) manage() {
|
func (t *tun) manage(reconnect time.Duration) {
|
||||||
reconnect := time.NewTicker(ReconnectTime)
|
r := time.NewTicker(reconnect)
|
||||||
defer reconnect.Stop()
|
defer r.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t.closed:
|
case <-t.closed:
|
||||||
return
|
return
|
||||||
case <-reconnect.C:
|
case <-r.C:
|
||||||
t.manageLinks()
|
t.manageLinks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -862,8 +862,11 @@ func (t *tun) setupLink(node string) (*link, error) {
|
|||||||
|
|
||||||
// create a new link
|
// create a new link
|
||||||
link := newLink(c)
|
link := newLink(c)
|
||||||
|
|
||||||
// set link id to remote side
|
// set link id to remote side
|
||||||
|
link.Lock()
|
||||||
link.id = c.Remote()
|
link.id = c.Remote()
|
||||||
|
link.Unlock()
|
||||||
|
|
||||||
// send the first connect message
|
// send the first connect message
|
||||||
if err := t.sendMsg("connect", link); err != nil {
|
if err := t.sendMsg("connect", link); err != nil {
|
||||||
@ -984,7 +987,7 @@ func (t *tun) Connect() error {
|
|||||||
t.setupLinks()
|
t.setupLinks()
|
||||||
|
|
||||||
// manage the links
|
// manage the links
|
||||||
go t.manage()
|
go t.manage(ReconnectTime)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user