mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	recover if p.doSend is closed due to a race between peers.doSendSwitchMsgs and peers.removePeer
This commit is contained in:
		
							parent
							
								
									f0c249a4b7
								
							
						
					
					
						commit
						cd514799da
					
				
					 1 changed files with 12 additions and 5 deletions
				
			
		| 
						 | 
					@ -166,17 +166,24 @@ func (ps *peers) sendSwitchMsgs() {
 | 
				
			||||||
		if p.port == 0 {
 | 
							if p.port == 0 {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							p.doSendSwitchMsgs()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// If called, sends a notification to the peer's linkLoop to trigger a switchMsg send.
 | 
				
			||||||
 | 
					// Mainly called by sendSwitchMsgs or during linkLoop startup.
 | 
				
			||||||
 | 
					func (p *peer) doSendSwitchMsgs() {
 | 
				
			||||||
 | 
						defer func() { recover() }() // In case there's a race with close(p.doSend)
 | 
				
			||||||
	select {
 | 
						select {
 | 
				
			||||||
	case p.doSend <- struct{}{}:
 | 
						case p.doSend <- struct{}{}:
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This must be launched in a separate goroutine by whatever sets up the peer struct.
 | 
					// This must be launched in a separate goroutine by whatever sets up the peer struct.
 | 
				
			||||||
// It handles link protocol traffic.
 | 
					// It handles link protocol traffic.
 | 
				
			||||||
func (p *peer) linkLoop() {
 | 
					func (p *peer) linkLoop() {
 | 
				
			||||||
	go func() { p.doSend <- struct{}{} }()
 | 
						go p.doSendSwitchMsgs()
 | 
				
			||||||
	tick := time.NewTicker(time.Second)
 | 
						tick := time.NewTicker(time.Second)
 | 
				
			||||||
	defer tick.Stop()
 | 
						defer tick.Stop()
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue