From 2ef823e69c7fd25cb6f1b18e3d9ca7ac965e4a9d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 4 Mar 2019 23:16:46 +0000 Subject: [PATCH] Fix deadlock when reconfiguring multicast --- src/yggdrasil/link.go | 13 ++++++++----- src/yggdrasil/tcp.go | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/yggdrasil/link.go b/src/yggdrasil/link.go index cbbdb5e9..c4f52a38 100644 --- a/src/yggdrasil/link.go +++ b/src/yggdrasil/link.go @@ -76,14 +76,17 @@ func (l *link) init(c *Core) error { go func() { for { e := <-l.reconfigure - response := make(chan error) - l.tcp.reconfigure <- response - if err := <-response; err != nil { + tcpresponse := make(chan error) + awdlresponse := make(chan error) + l.tcp.reconfigure <- tcpresponse + if err := <-tcpresponse; err != nil { e <- err + continue } - l.awdl.reconfigure <- response - if err := <-response; err != nil { + l.awdl.reconfigure <- awdlresponse + if err := <-awdlresponse; err != nil { e <- err + continue } e <- nil } diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 74f14d8a..80d9ccdb 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -16,6 +16,7 @@ package yggdrasil import ( "context" + "errors" "fmt" "math/rand" "net" @@ -57,10 +58,10 @@ func (t *tcp) getAddr() *net.TCPAddr { // to multicast.go, which obviously is not great, but right now multicast.go // doesn't have the ability to send more than one address in a packet either t.mutex.Lock() + defer t.mutex.Unlock() for _, listener := range t.listeners { return listener.Addr().(*net.TCPAddr) } - t.mutex.Unlock() return nil } @@ -85,6 +86,7 @@ func (t *tcp) init(l *link) error { if len(added) > 0 || len(deleted) > 0 { for _, add := range added { if add[:6] != "tcp://" { + e <- errors.New("unknown scheme: " + add) continue } if err := t.listen(add[6:]); err != nil {