mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	recover if we try to send to a closed session worker due to a race between a Conn.Write call and a Conn.Close call
This commit is contained in:
		
							parent
							
								
									28db566b37
								
							
						
					
					
						commit
						d39428735d
					
				
					 1 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
					@ -236,6 +236,11 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
 | 
				
			||||||
	timer := getDeadlineTimer(&c.writeDeadline)
 | 
						timer := getDeadlineTimer(&c.writeDeadline)
 | 
				
			||||||
	defer util.TimerStop(timer)
 | 
						defer util.TimerStop(timer)
 | 
				
			||||||
	// Hand over to the session worker
 | 
						// Hand over to the session worker
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							if recover() != nil {
 | 
				
			||||||
 | 
								err = errors.New("write failed")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}() // In case we're racing with a close
 | 
				
			||||||
	select { // Send to worker
 | 
						select { // Send to worker
 | 
				
			||||||
	case sinfo.worker <- workerFunc:
 | 
						case sinfo.worker <- workerFunc:
 | 
				
			||||||
	case <-timer.C:
 | 
						case <-timer.C:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue