>From 4c9cf7b7cb17fe82a9854a86a327a400e22d0774 Mon Sep 17 00:00:00 2001
From: Santiago Vila <sanvila@debian.org>
Date: Sat, 24 Oct 2026 00:21:25 +0200
Subject: [PATCH 1/2] Fix "Address already in use: AH00072: make_sock: could
 not bind to address 127.0.0.1:xxx". Closes: #1035983.

---
 .../patches/fix-address-already-in-use.patch  | 258 ++++++++++++++++++
 debian/patches/series                         |   1 +
 2 files changed, 259 insertions(+)
 create mode 100644 debian/patches/fix-address-already-in-use.patch

diff --git a/debian/patches/fix-address-already-in-use.patch b/debian/patches/fix-address-already-in-use.patch
new file mode 100644
index 00000000..0ebb0108
--- /dev/null
+++ b/debian/patches/fix-address-already-in-use.patch
@@ -0,0 +1,258 @@
+From: Santiago Vila <sanvila@debian.org>
+Subject: tests: use ports 27524-27528 instead of 47524-47528
+Bug-Debian: https://bugs.debian.org/1035983
+
+The Apache test server ports were above the kernel's default ephemeral
+port range (net.ipv4.ip_local_port_range starts at 32768). The test
+clients make many loopback connections, so one of them could be assigned
+one of those ports; the resulting TIME_WAIT socket then made Apache fail
+to bind its listener, because SO_REUSEADDR on the listener does not
+override a client-created TIME_WAIT socket.
+
+Move the test ports below the ephemeral range to avoid these random bind
+failures.
+
+This commit should fix errors like this:
+
+Address already in use: AH00072: make_sock: could not bind to address 127.0.0.1:xxx
+
+--- a/tests/auth-test.c
++++ b/tests/auth-test.c
+@@ -1767,14 +1767,14 @@
+ 	const char *url;
+ 	guint status;
+ } uri_tests[] = {
+-	{ "http://user1:realm1@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_OK },
+-	{ "http://user1:wrong@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
+-	{ "http://user1@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
+-	{ "http://user5:realm1@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
+-	{ "http://127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
+-	{ "http://user4@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_OK },
+-	{ "http://user4:@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_OK },
+-	{ "http://user4:wrong@127.0.0.1:47524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
++	{ "http://user1:realm1@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_OK },
++	{ "http://user1:wrong@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
++	{ "http://user1@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
++	{ "http://user5:realm1@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
++	{ "http://127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
++	{ "http://user4@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_OK },
++	{ "http://user4:@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_OK },
++	{ "http://user4:wrong@127.0.0.1:27524/Digest/realm1/", SOUP_STATUS_UNAUTHORIZED },
+ };
+ 
+ static void
+@@ -2003,7 +2003,7 @@
+ 	test_init (argc, argv, NULL);
+ 	apache_init ();
+ 
+-	base_uri = "http://127.0.0.1:47524/";
++	base_uri = "http://127.0.0.1:27524/";
+ 
+ 	g_test_add_data_func ("/auth/main-tests", main_tests, do_batch_tests);
+ 	g_test_add_data_func ("/auth/relogin-tests", relogin_tests, do_batch_tests);
+--- a/tests/connection-test.c
++++ b/tests/connection-test.c
+@@ -670,10 +670,10 @@
+ 	soup_test_session_abort_unref (session);
+ }
+ 
+-#define HTTP_SERVER          "http://127.0.0.1:47524"
++#define HTTP_SERVER          "http://127.0.0.1:27524"
+ #define HTTP_SERVER_BAD_PORT "http://127.0.0.1:1234"
+-#define HTTPS_SERVER         "https://127.0.0.1:47525"
+-#define HTTP_PROXY           "http://127.0.0.1:47526"
++#define HTTPS_SERVER         "https://127.0.0.1:27525"
++#define HTTP_PROXY           "http://127.0.0.1:27526"
+ 
+ static const char *state_names[] = {
+ 	"NEW", "CONNECTING", "IDLE", "IN_USE",
+@@ -997,7 +997,7 @@
+         g_assert_cmpstr (ip_address, ==, "127.0.0.1");
+         g_free (ip_address);
+         if (G_IS_PROXY_ADDRESS (remote_address)) {
+-                g_assert_cmpuint (g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (remote_address)), ==, 47526);
++                g_assert_cmpuint (g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (remote_address)), ==, 27526);
+                 g_assert_cmpuint (g_proxy_address_get_destination_port (G_PROXY_ADDRESS (remote_address)), ==, g_uri_get_port (soup_message_get_uri (msg)));
+                 g_assert_cmpstr (g_proxy_address_get_destination_hostname (G_PROXY_ADDRESS (remote_address)), ==, "127.0.0.1");
+         } else {
+@@ -1675,7 +1675,7 @@
+ 
+         session = soup_test_session_new (NULL);
+ 
+-        msg = soup_message_new ("GET", "https://127.0.0.1:47525/client-cert");
++        msg = soup_message_new ("GET", "https://127.0.0.1:27525/client-cert");
+         soup_message_set_force_http_version (msg, SOUP_HTTP_2_0);
+         g_signal_connect (msg, "restarted",
+                           G_CALLBACK (message_restarted), &was_restarted);
+--- a/tests/httpd.conf.in
++++ b/tests/httpd.conf.in
+@@ -1,7 +1,7 @@
+ # http.conf used for testing auth-test
+ 
+ ServerName 127.0.0.1
+-Listen 127.0.0.1:47524
++Listen 127.0.0.1:27524
+ 
+ DocumentRoot .
+ 
+@@ -34,16 +34,16 @@
+ DirectoryIndex index.txt
+ TypesConfig /dev/null
+ Redirect permanent /redirected /index.txt
+-Redirect permanent /Basic/realm1/redirected https://127.0.0.1:47525/index.txt
++Redirect permanent /Basic/realm1/redirected https://127.0.0.1:27525/index.txt
+ 
+ # Prefer http1 for now because most of the tests expect http1 behavior.
+ Protocols http/1.1 h2
+ 
+ # Proxy #1: unauthenticated
+-Listen 127.0.0.1:47526
+-<VirtualHost 127.0.0.1:47526>
++Listen 127.0.0.1:27526
++<VirtualHost 127.0.0.1:27526>
+   ProxyRequests On
+-  AllowCONNECT 47525
++  AllowCONNECT 27525
+ 
+   # Deny proxying by default
+   <Proxy *>
+@@ -56,7 +56,7 @@
+   </Proxy>
+ 
+   # Allow CONNECT to local https port
+-  <Proxy 127.0.0.1:47525>
++  <Proxy 127.0.0.1:27525>
+     Require all granted
+   </Proxy>
+ 
+@@ -67,10 +67,10 @@
+ </VirtualHost>
+ 
+ # Proxy #2: authenticated
+-Listen 127.0.0.1:47527
+-<VirtualHost 127.0.0.1:47527>
++Listen 127.0.0.1:27527
++<VirtualHost 127.0.0.1:27527>
+   ProxyRequests On
+-  AllowCONNECT 47525
++  AllowCONNECT 27525
+ 
+   # Deny proxying by default
+   <Proxy *>
+@@ -78,7 +78,7 @@
+   </Proxy>
+ 
+   # Allow local http connections with authentication
+-  <Proxy http://127.0.0.1:47524*>
++  <Proxy http://127.0.0.1:27524*>
+     AuthType Basic
+     AuthName realm1
+     AuthUserFile ./htpasswd
+@@ -86,7 +86,7 @@
+   </Proxy>
+ 
+   # Allow CONNECT to local https port with authentication
+-  <Proxy 127.0.0.1:47525>
++  <Proxy 127.0.0.1:27525>
+     AuthType Basic
+     AuthName realm1
+     AuthUserFile ./htpasswd
+@@ -100,10 +100,10 @@
+ </VirtualHost>
+ 
+ # Proxy #3: unauthenticatable-to
+-Listen 127.0.0.1:47528
+-<VirtualHost 127.0.0.1:47528>
++Listen 127.0.0.1:27528
++<VirtualHost 127.0.0.1:27528>
+   ProxyRequests On
+-  AllowCONNECT 47525
++  AllowCONNECT 27525
+ 
+   # Deny proxying by default
+   <Proxy *>
+@@ -111,7 +111,7 @@
+   </Proxy>
+ 
+   # Allow local http connections with authentication
+-  <Proxy http://127.0.0.1:47524*>
++  <Proxy http://127.0.0.1:27524*>
+     AuthType Basic
+     AuthName realm1
+     AuthUserFile ./htpasswd
+@@ -119,7 +119,7 @@
+   </Proxy>
+ 
+   # Allow CONNECT to local https port with authentication
+-  <Proxy 127.0.0.1:47525>
++  <Proxy 127.0.0.1:27525>
+     AuthType Basic
+     AuthName realm1
+     AuthUserFile ./htpasswd
+@@ -135,9 +135,9 @@
+ 
+ # SSL setup
+ <IfModule mod_ssl.c>
+-  Listen 127.0.0.1:47525
++  Listen 127.0.0.1:27525
+ 
+-  <VirtualHost 127.0.0.1:47525>
++  <VirtualHost 127.0.0.1:27525>
+     SSLEngine on
+ 
+     SSLCertificateFile ./test-cert.pem
+--- a/tests/multithread-test.c
++++ b/tests/multithread-test.c
+@@ -38,8 +38,8 @@
+         BasicTestFlags flags;
+ } Test;
+ 
+-#define HTTPS_SERVER "https://127.0.0.1:47525"
+-#define HTTP_PROXY   "http://127.0.0.1:47526"
++#define HTTPS_SERVER "https://127.0.0.1:27525"
++#define HTTP_PROXY   "http://127.0.0.1:27526"
+ 
+ static void
+ test_setup (Test *test, gconstpointer data)
+--- a/tests/proxy-test.c
++++ b/tests/proxy-test.c
+@@ -17,12 +17,12 @@
+ 	{ "GET -> 401 -> 200", "/Basic/realm1/", SOUP_STATUS_OK, NULL },
+ 	{ "GET -> 401 -> 401", "/Basic/realm2/", SOUP_STATUS_UNAUTHORIZED, NULL },
+ 	{ "GET -> 403", "http://no-such-hostname.xx/", SOUP_STATUS_FORBIDDEN, "577532" },
+-	{ "GET -> 200 (unproxied)", "http://localhost:47524/", SOUP_STATUS_OK, "700472" },
++	{ "GET -> 200 (unproxied)", "http://localhost:27524/", SOUP_STATUS_OK, "700472" },
+ };
+ static const int ntests = sizeof (tests) / sizeof (tests[0]);
+ 
+-#define HTTP_SERVER    "http://127.0.0.1:47524"
+-#define HTTPS_SERVER   "https://127.0.0.1:47525"
++#define HTTP_SERVER    "http://127.0.0.1:27524"
++#define HTTPS_SERVER   "https://127.0.0.1:27525"
+ 
+ enum {
+ 	SIMPLE_PROXY,
+@@ -30,9 +30,9 @@
+ 	UNAUTH_PROXY
+ };
+ static const char *proxies[] = {
+-	"http://127.0.0.1:47526",
+-	"http://127.0.0.1:47527",
+-	"http://127.0.0.1:47528"
++	"http://127.0.0.1:27526",
++	"http://127.0.0.1:27527",
++	"http://127.0.0.1:27528"
+ };
+ static const char *proxy_names[] = {
+ 	"simple proxy",
+--- a/tests/range-test.c
++++ b/tests/range-test.c
+@@ -883,7 +883,7 @@
+ 
+ 	session = soup_test_session_new (NULL);
+ 
+-	do_range_test (session, "http://127.0.0.1:47524/", TRUE, FALSE);
++	do_range_test (session, "http://127.0.0.1:27524/", TRUE, FALSE);
+ 
+ 	soup_test_session_abort_unref (session);
+ }
diff --git a/debian/patches/series b/debian/patches/series
index fc9f346f..848f3942 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,3 +5,4 @@ tests-extend-timeout-for-http2-body-stream-test.patch
 tests-Treat-multithread-test-as-an-Apache-test.patch
 Revert-logger-test-change-that-doesn-t-work-on-32-bit-arc.patch
 tests-remove-syntax-no-longer-accepted-with-Apache-2.4.69.patch
+fix-address-already-in-use.patch
-- 
2.47.3

