فهرست منبع

Fix: race condition writing to conn.Conn

Rod Hynes 11 سال پیش
والد
کامیت
6bf225f45b
1فایلهای تغییر یافته به همراه7 افزوده شده و 1 حذف شده
  1. 7 1
      psiphon/TCPConn_unix.go

+ 7 - 1
psiphon/TCPConn_unix.go

@@ -119,11 +119,17 @@ func interruptibleTCPDial(addr string, config *DialConfig) (conn *TCPConn, err e
 	// Convert the syscall socket to a net.Conn
 	file := os.NewFile(uintptr(conn.interruptible.socketFd), "")
 	defer file.Close()
-	conn.Conn, err = net.FileConn(file)
+	fileConn, err := net.FileConn(file)
 	if err != nil {
 		return nil, ContextError(err)
 	}
 
+	// Need mutex to write conn.Conn since conn remains in pendingConns, from
+	// where conn.Close() may be called in another goroutine
+	conn.mutex.Lock()
+	conn.Conn = fileConn
+	conn.mutex.Unlock()
+
 	// Going through upstream HTTP proxy
 	if config.UpstreamHttpProxyAddress != "" {
 		// This call can be interrupted by closing the pending conn