Browse Source

lib/dialer: Add env var to disable proxy fallback (fixes #3006)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3009
Audrius Butkevicius 9 years ago
parent
commit
2467678bd4
1 changed files with 8 additions and 0 deletions
  1. 8 0
      lib/dialer/internal.go

+ 8 - 0
lib/dialer/internal.go

@@ -23,6 +23,7 @@ var (
 	l           = logger.DefaultLogger.NewFacility("dialer", "Dialing connections")
 	proxyDialer = getDialer(proxy.Direct)
 	usingProxy  = proxyDialer != proxy.Direct
+	noFallback  = os.Getenv("ALL_PROXY_NO_FALLBACK") != ""
 )
 
 type dialFunc func(network, addr string) (net.Conn, error)
@@ -40,6 +41,9 @@ func init() {
 		go func() {
 			time.Sleep(500 * time.Millisecond)
 			l.Infoln("Proxy settings detected")
+			if noFallback {
+				l.Infoln("Proxy fallback disabled")
+			}
 		}()
 	} else {
 		go func() {
@@ -62,6 +66,10 @@ func dialWithFallback(proxyDialFunc dialFunc, fallbackDialFunc dialFunc, network
 	}
 	l.Debugf("Dialing %s address %s via proxy - error %s", network, addr, err)
 
+	if noFallback {
+		return conn, err
+	}
+
 	conn, err = fallbackDialFunc(network, addr)
 	if err == nil {
 		l.Debugf("Dialing %s address %s via fallback - success, %s -> %s", network, addr, conn.LocalAddr(), conn.RemoteAddr())