mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	remove session shutdown goroutine, just send a message instead
This commit is contained in:
		
							parent
							
								
									b2a2e251ad
								
							
						
					
					
						commit
						dffd70119d
					
				
					 2 changed files with 8 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue