Просмотр исходного кода

Workaround net.FileConn RemoteAddr nil issue

Rod Hynes 7 лет назад
Родитель
Сommit
ed99f5792b
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      psiphon/TCPConn_bind.go

+ 11 - 0
psiphon/TCPConn_bind.go

@@ -261,6 +261,17 @@ func tcpDial(ctx context.Context, addr string, config *DialConfig) (net.Conn, er
 			continue
 		}
 
+		// Handle the case where net.FileConn produces a Conn where RemoteAddr
+		// unexpectedly returns nil: https://github.com/golang/go/issues/23022.
+		//
+		// The net.Conn interface indicates that RemoteAddr returns a usable value,
+		// and code such as crypto/tls, in loadSession/clientSessionCacheKey, uses
+		// the RemoteAddr return value without a nil check, resulting in an panic.
+		if conn.RemoteAddr() == nil {
+			conn.Close()
+			return nil, common.ContextError(errors.New("RemoteAddr returns nil"))
+		}
+
 		return &TCPConn{Conn: conn}, nil
 	}