On Tue, Aug 18, 2026 at 12:25:35PM -0300, Antonio Terceiro wrote:
> Package: release.debian.org
> Severity: normal
> Tags: trixie
> X-Debbugs-Cc: [email protected]
> Control: affects -1 + src:auto-apt-proxy
> User: [email protected]
> Usertags: pu
> 
> [ Reason ]
> auto-apt-proxy is a helper tool for APT that automatically detects APT
> proxies on the local network. In some networking configurations it might
> enter an infinite loop. This bug is 

Sorry this sentence was left incomplete. I meant to say that this is bug
#1142542.

Additionally, I would like to include a second patch, that causes
auto-apt-proxy to wait for the network to be online. In some use cases,
such as in Debian CI (ci.debian.net), apt might be used right away after
the machine starts, and that sometimes means even before the network is
configured, causing excessive use of external connectivity which is
limited for those hosts (and thus why we need to use a proxy on them).
This change uses that same mechanism that apt-daily.service uses, which
is `apt-helper wait-online`.

Please find attached an update diff WRT the version currently in trixie.

> [ Impact ]
> auto-apt-proxy might not only not detect a proxy, but will also go into
> a infinite loop and prevent APT from working entirely.
> 
> [ Tests ]
> All the autopkgtest pass with this change. The bug reporter also
> confirmed that the change fixes things for them.
> 
> [ Risks ]
> The change is trivial and risk is minimal, if not zero.
> 
> [ Checklist ]
>   [x] *all* changes are documented in the d/changelog
>   [x] I reviewed all changes and I approve them
>   [x] attach debdiff against the package in (old)stable
>   [x] the issue is verified as fixed in unstable
> 
> [ Changes ]
> The call to `apt-helper download-file` will now receive an extra option
> telling it to not use an APT proxy autodetection command, which would
> cause auto-apt-proxy to be called again.
> 
> There is also a change to one of the test cases that is currently
> failing in trixie. That test case is not a problem for forky because
> there the default timeout for network operations has been changed to 1s
> instead of 5.
> 
> [ Other info ]
> n/a

Everything else in the original report still applies.
diff --git a/README.md b/README.md
index 4d3347e..ec81840 100644
--- a/README.md
+++ b/README.md
@@ -86,6 +86,21 @@ detected proxy to `stdout`, as `apt` expects. To enable logging, set the
 `AUTO_APT_PROXY_DEBUG` environment variable to a non-empty string and
 **auto-apt-proxy** will log debugging messages to `stderr`.
 
+# WAITING TO BE ONLINE
+
+Starting with version 18, auto-apt-proxy will wait for the network to be
+online before attempting to detect any proxies. This is done by calling
+`/usr/lib/apt/apt-helper wait-online`, and is intended to help with cases
+where:
+
+1. the network takes some time to start;
+1. apt is used right away after booting, even before the network is fully up;
+1. the first `auto-apt-proxy` call fails to find a proxy, and that gets
+   cached.
+
+To disable this behaviour, you can set the `AUTO_APT_PROXY_NO_WAIT_ONLINE`
+environment variable to any non-empty value.
+
 # EXAMPLES
 
 $ **auto-apt-proxy**
diff --git a/auto-apt-proxy b/auto-apt-proxy
index b730234..c70858b 100755
--- a/auto-apt-proxy
+++ b/auto-apt-proxy
@@ -74,9 +74,22 @@ proxy_url() {
   esac
 }
 
+wait_online() {
+  if [ -n "${AUTO_APT_PROXY_NO_WAIT_ONLINE:-}" ]; then
+    return
+  fi
+  # apt-helper wait-online already has a timeout of its own, of 30s. That
+  # should to be enough for most systems to come online.
+  log_debug "Waiting for network to be online"
+  if ! /usr/lib/apt/apt-helper wait-online; then
+    exit
+  fi
+}
+
 hit() {
   timeout 5 /usr/lib/apt/apt-helper \
     -o Acquire::http::Proxy=DIRECT -o Acquire::Retries=0 \
+    -o Acquire::http::Proxy-Auto-Detect= \
     download-file "$@" "$output" 2>&1
 }
 
@@ -321,6 +334,8 @@ container_host() {
 }
 
 __detect__() {
+  wait_online
+
   sources="
     v4_localhost
     v4_addresses
diff --git a/debian/changelog b/debian/changelog
index a8cccf7..d34d35a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+auto-apt-proxy (16.8+deb13u2) trixie; urgency=medium
+
+  * hit(): prevent apt-helper call from recursing into auto-apt-proxy
+    (Closes: #1142542)
+  * wait for network to be online
+  * debian/tests/timeout: fix tests to be more reliable
+
+ -- Antonio Terceiro <[email protected]>  Tue, 18 Aug 2026 12:13:08 -0300
+
 auto-apt-proxy (16.8+deb13u1) trixie; urgency=medium
 
   * Check explicitly configured proxies before network gateway
diff --git a/debian/tests/noproxy b/debian/tests/noproxy
index 8750ef1..53d14ef 100755
--- a/debian/tests/noproxy
+++ b/debian/tests/noproxy
@@ -3,6 +3,7 @@
 set -eu
 
 export AUTO_APT_PROXY_NO_CACHE=1
+export AUTO_APT_PROXY_NO_WAIT_ONLINE=1
 
 if ! newnet true; then
   echo "I: cannot use user namespaces"
diff --git a/debian/tests/timeout b/debian/tests/timeout
index 08a8c26..3d1e026 100755
--- a/debian/tests/timeout
+++ b/debian/tests/timeout
@@ -14,10 +14,10 @@ class TimeoutProxy
 end
 run TimeoutProxy.new
 PROXY
-rackup --daemonize --pid proxy.pid --port 9999
+rackup --daemonize --pid proxy.pid --host 127.0.0.1 --port 9999
 trap 'kill -9 $(cat proxy.pid)' INT TERM EXIT
 
 set -x
 
-# auto-apt-proxy should timeout and exit 0 in less than 15 seconds
-timeout --signal=KILL 15 auto-apt-proxy
+# auto-apt-proxy should timeout and exit 0 in less than 60 seconds
+timeout --signal=KILL 60 auto-apt-proxy

Attachment: signature.asc
Description: PGP signature

Reply via email to