mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Don't indefinitely block TUN/TAP reader goroutine when a conn error happens
This commit is contained in:
		
							parent
							
								
									396c879d0f
								
							
						
					
					
						commit
						9e086e70f0
					
				
					 2 changed files with 8 additions and 3 deletions
				
			
		| 
						 | 
					@ -58,13 +58,18 @@ func (s *tunConn) reader() error {
 | 
				
			||||||
			// TODO don't start a new goroutine for every packet read, this is probably a big part of the slowdowns we saw when refactoring
 | 
								// TODO don't start a new goroutine for every packet read, this is probably a big part of the slowdowns we saw when refactoring
 | 
				
			||||||
			if n, err = s.conn.Read(b); err != nil {
 | 
								if n, err = s.conn.Read(b); err != nil {
 | 
				
			||||||
				s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn read error:", err)
 | 
									s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn read error:", err)
 | 
				
			||||||
 | 
									if e, eok := err.(yggdrasil.ConnError); eok && !e.Temporary() {
 | 
				
			||||||
 | 
										close(s.stop)
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										read <- false
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			read <- true
 | 
								read <- true
 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-read:
 | 
							case r := <-read:
 | 
				
			||||||
			if n > 0 {
 | 
								if r && n > 0 {
 | 
				
			||||||
				bs := append(util.GetBytes(), b[:n]...)
 | 
									bs := append(util.GetBytes(), b[:n]...)
 | 
				
			||||||
				select {
 | 
									select {
 | 
				
			||||||
				case s.tun.send <- bs:
 | 
									case s.tun.send <- bs:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -207,7 +207,7 @@ func (c *Conn) Read(b []byte) (int, error) {
 | 
				
			||||||
			defer close(done)
 | 
								defer close(done)
 | 
				
			||||||
			// If the nonce is bad then drop the packet and return an error
 | 
								// If the nonce is bad then drop the packet and return an error
 | 
				
			||||||
			if !sinfo.nonceIsOK(&p.Nonce) {
 | 
								if !sinfo.nonceIsOK(&p.Nonce) {
 | 
				
			||||||
				err = errors.New("packet dropped due to invalid nonce")
 | 
									err = ConnError{errors.New("packet dropped due to invalid nonce"), false, true, 0}
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// Decrypt the packet
 | 
								// Decrypt the packet
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue