mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Hopefully fix a concurrent map read-write when removing peers
This commit is contained in:
		
							parent
							
								
									401960e17e
								
							
						
					
					
						commit
						1d00131416
					
				
					 2 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -127,7 +127,7 @@ func (ps *peers) removePeer(port switchPort) {
 | 
			
		|||
		return
 | 
			
		||||
	} // Can't remove self peer
 | 
			
		||||
	ps.core.router.doAdmin(func() {
 | 
			
		||||
		ps.core.switchTable.unlockedRemovePeer(port)
 | 
			
		||||
		ps.core.switchTable.forgetPeer(port)
 | 
			
		||||
	})
 | 
			
		||||
	ps.mutex.Lock()
 | 
			
		||||
	oldPorts := ps.getPorts()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -242,7 +242,9 @@ func (t *switchTable) cleanRoot() {
 | 
			
		|||
// Removes a peer.
 | 
			
		||||
// Must be called by the router mainLoop goroutine, e.g. call router.doAdmin with a lambda that calls this.
 | 
			
		||||
// If the removed peer was this node's parent, it immediately tries to find a new parent.
 | 
			
		||||
func (t *switchTable) unlockedRemovePeer(port switchPort) {
 | 
			
		||||
func (t *switchTable) forgetPeer(port switchPort) {
 | 
			
		||||
	t.mutex.Lock()
 | 
			
		||||
	defer t.mutex.Unlock()
 | 
			
		||||
	delete(t.data.peers, port)
 | 
			
		||||
	t.updater.Store(&sync.Once{})
 | 
			
		||||
	if port != t.parent {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue