mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	slight cleanup of dial's timeout
This commit is contained in:
		
							parent
							
								
									681c8ca6f9
								
							
						
					
					
						commit
						ea085663ea
					
				
					 1 changed files with 4 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -72,19 +72,16 @@ func (d *Dialer) DialByNodeIDandMask(ctx context.Context, nodeID, nodeMask *cryp
 | 
			
		|||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	conn.session.setConn(nil, conn)
 | 
			
		||||
	var c context.Context
 | 
			
		||||
	var cancel context.CancelFunc
 | 
			
		||||
	const timeout = 6 * time.Second
 | 
			
		||||
	if ctx != nil {
 | 
			
		||||
		c, cancel = context.WithTimeout(ctx, timeout)
 | 
			
		||||
	} else {
 | 
			
		||||
		c, cancel = context.WithTimeout(context.Background(), timeout)
 | 
			
		||||
	if ctx == nil {
 | 
			
		||||
		ctx = context.Background()
 | 
			
		||||
	}
 | 
			
		||||
	ctx, cancel = context.WithTimeout(ctx, 6*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
	select {
 | 
			
		||||
	case <-conn.session.init:
 | 
			
		||||
		return conn, nil
 | 
			
		||||
	case <-c.Done():
 | 
			
		||||
	case <-ctx.Done():
 | 
			
		||||
		conn.Close()
 | 
			
		||||
		return nil, errors.New("session handshake timeout")
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue