Преглед изворни кода

Ensure passthrough is not interrupted by a pre-existing deadline

mirokuratczyk пре 2 година
родитељ
комит
66a520ce7e
1 измењених фајлова са 6 додато и 1 уклоњено
  1. 6 1
      psiphon/common/transforms/httpNormalizer.go

+ 6 - 1
psiphon/common/transforms/httpNormalizer.go

@@ -575,10 +575,16 @@ func passthrough(conn net.Conn, address string, dialer func(network, address str
 
 	defer conn.Close()
 
+	// Remove any pre-existing deadlines to ensure the passthrough
+	// is not interrupted.
+	_ = conn.SetDeadline(time.Time{})
+
 	passthroughConn, err := dialer("tcp", address)
 	if err != nil {
 		return
 	}
+	defer passthroughConn.Close()
+
 	_, err = passthroughConn.Write(buf)
 	if err != nil {
 		return
@@ -588,7 +594,6 @@ func passthrough(conn net.Conn, address string, dialer func(network, address str
 		_, _ = io.Copy(passthroughConn, conn)
 		passthroughConn.Close()
 	}()
-
 	_, _ = io.Copy(conn, passthroughConn)
 }