diff --git a/src/yggdrasil/dialer.go b/src/yggdrasil/dialer.go index db5d5a4d..6b24cfb4 100644 --- a/src/yggdrasil/dialer.go +++ b/src/yggdrasil/dialer.go @@ -69,7 +69,6 @@ func (d *Dialer) DialByNodeIDandMask(nodeID, nodeMask *crypto.NodeID) (*Conn, er defer t.Stop() select { case <-conn.session.init: - conn.session.startWorkers() return conn, nil case <-t.C: conn.Close() diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 57522209..7cd92db9 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -259,6 +259,7 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo { <-sinfo.cancel.Finished() sinfo.core.router.doAdmin(sinfo.close) }() + go sinfo.startWorkers() return &sinfo } @@ -386,7 +387,6 @@ func (ss *sessions) handlePing(ping *sessionPing) { for i := range conn.nodeMask { conn.nodeMask[i] = 0xFF } - conn.session.startWorkers() c := ss.listener.conn go func() { c <- conn }() } @@ -568,6 +568,12 @@ func (sinfo *sessionInfo) recvWorker() { } } }() + select { + case <-sinfo.cancel.Finished(): + return + case <-sinfo.init: + // Wait until the session has finished initializing before processing any packets + } for { for len(callbacks) > 0 { select { @@ -634,6 +640,12 @@ func (sinfo *sessionInfo) sendWorker() { util.WorkerGo(poolFunc) callbacks = append(callbacks, ch) } + select { + case <-sinfo.cancel.Finished(): + return + case <-sinfo.init: + // Wait until the session has finished initializing before processing any packets + } for { for len(callbacks) > 0 { select {