remove session shutdown goroutine, just send a message instead

This commit is contained in:
Arceliar 2019-08-25 19:13:47 -05:00
parent b2a2e251ad
commit dffd70119d
2 changed files with 8 additions and 7 deletions

View File

@ -304,6 +304,8 @@ func (c *Conn) Close() (err error) {
// Close the session, if it hasn't been closed already
if e := c.session.cancel.Cancel(errors.New("connection closed")); e != nil {
err = ConnError{errors.New("close failed, session already closed"), false, false, true, 0}
} else {
c.session.doRemove()
}
}
})

View File

@ -255,13 +255,6 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo {
sinfo.theirSubnet = *address.SubnetForNodeID(crypto.GetNodeID(&sinfo.theirPermPub))
ss.sinfos[sinfo.myHandle] = &sinfo
ss.byTheirPerm[sinfo.theirPermPub] = &sinfo.myHandle
go func() {
// Run cleanup when the session is canceled
<-sinfo.cancel.Finished()
sinfo.sessions.router.doAdmin(func() {
sinfo.sessions.removeSession(&sinfo)
})
}()
return &sinfo
}
@ -293,6 +286,12 @@ func (ss *sessions) cleanup() {
ss.lastCleanup = time.Now()
}
func (sinfo *sessionInfo) doRemove() {
sinfo.sessions.router.RecvFrom(nil, func() {
sinfo.sessions.removeSession(sinfo)
})
}
// Closes a session, removing it from sessions maps.
func (ss *sessions) removeSession(sinfo *sessionInfo) {
if s := sinfo.sessions.sinfos[sinfo.myHandle]; s == sinfo {