From 7d58a7ef3e8be7a0df386db7e79ed9c0de91ba62 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 29 Jun 2019 17:44:28 -0500 Subject: [PATCH] fix channel multiple close bug and concurrency bug in the way sessionInfo.close was being called --- src/yggdrasil/conn.go | 2 +- src/yggdrasil/session.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/conn.go b/src/yggdrasil/conn.go index 53d2551..38e4df9 100644 --- a/src/yggdrasil/conn.go +++ b/src/yggdrasil/conn.go @@ -256,7 +256,7 @@ func (c *Conn) Close() error { defer c.mutex.Unlock() if c.session != nil { // Close the session, if it hasn't been closed already - c.session.close() + c.core.router.doAdmin(c.session.close) } // This can't fail yet - TODO? c.closed = true diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 98a12c7..4cc059e 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -269,8 +269,11 @@ func (ss *sessions) cleanup() { // Closes a session, removing it from sessions maps and killing the worker goroutine. func (sinfo *sessionInfo) close() { - delete(sinfo.core.sessions.sinfos, sinfo.myHandle) - delete(sinfo.core.sessions.byTheirPerm, sinfo.theirPermPub) + if s := sinfo.core.sessions.sinfos[sinfo.myHandle]; s == sinfo { + delete(sinfo.core.sessions.sinfos, sinfo.myHandle) + delete(sinfo.core.sessions.byTheirPerm, sinfo.theirPermPub) + } + defer func() { recover() }() close(sinfo.worker) }