1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Fixed tunnel race conditions. (#1094)

This commit is contained in:
Milos Gajdos 2020-01-08 14:48:38 +00:00 committed by Asim Aslam
parent 59fccb82ec
commit 78aed5beed

View File

@ -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
func (t *tun) manage() {
reconnect := time.NewTicker(ReconnectTime)
defer reconnect.Stop()
func (t *tun) manage(reconnect time.Duration) {
r := time.NewTicker(reconnect)
defer r.Stop()
for {
select {
case <-t.closed:
return
case <-reconnect.C:
case <-r.C:
t.manageLinks()
}
}
@ -862,8 +862,11 @@ func (t *tun) setupLink(node string) (*link, error) {
// create a new link
link := newLink(c)
// set link id to remote side
link.Lock()
link.id = c.Remote()
link.Unlock()
// send the first connect message
if err := t.sendMsg("connect", link); err != nil {
@ -984,7 +987,7 @@ func (t *tun) Connect() error {
t.setupLinks()
// manage the links
go t.manage()
go t.manage(ReconnectTime)
return nil
}