Skip to content

core: Fix ListenCoresBucketsRatio losing IPv6 on duplicated listeners - #1042

Open
arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz69804-listencbratio-ipv6-family
Open

arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz69804-listencbratio-ipv6-family

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

ap_duplicate_listeners() re-resolves each original listener's address with apr_sockaddr_info_get(hostname, APR_UNSPEC, ...) to create the extra per-bucket sockets. For a wildcard Listen <port> (hostname is NULL), APR_UNSPEC leaves the resolution to the system, which can return a different family than the original listener actually bound (IPv6 dual-stack on Linux here): all duplicated buckets came back as plain IPv4 sockets, leaving only the original socket able to accept IPv6 connections.

Pass the original listener's own family instead of APR_UNSPEC, so every duplicated bucket matches it.

Verified on a real server: with Listen <port> + ListenCoresBucketsRatio 1 (16 cores), before the fix ss showed 15 IPv4 sockets and 1 IPv6 socket for the port; after the fix, all 16 are IPv6. Added a pytest regression test asserting this via /proc/net/tcp[6].

PR: https://bz.apache.org/bugzilla/show_bug.cgi?id=69804


Checklist: not a security report (SECURITY.md); follows the style guide; no new log messages added; changes-entries/69804.txt included; pytest test added under test/modules/core.

@arturobernalg arturobernalg changed the title core: Fix ListenCoresBucketsRatio losing IPv6 on duplicated core: Fix ListenCoresBucketsRatio losing IPv6 on duplicated listenerslisteners core: Fix ListenCoresBucketsRatio losing IPv6 on duplicated listeners Nov 16, 2026
@arturobernalg
arturobernalg force-pushed the fix/bz69804-listencbratio-ipv6-family branch from 5b0a29a to 9a3b3f6 Compare November 16, 2026 07:43
@Firefishy

Copy link
Copy Markdown

Thank you. I'm the poster of bug report to apache bugzilla.

If needed, the workaround is to ONLY listen on IPv6 (which also accepts IPv4 connections)

# IPv6 listen to workaround bug: https://bz.apache.org/bugzilla/show_bug.cgi?id=69804
# Listen on port 80
Listen [::]:80

# Listen on port 443 if mod_ssl is enabled
<IfModule mod_ssl.c>
    Listen [::]:443
</IfModule>

# Listen on port 443 if mod_gnutls is enabled
<IfModule mod_gnutls.c>
    Listen [::]:443
</IfModule>

@ylavic

ylavic commented Nov 30, 2026

Copy link
Copy Markdown
Member

Looks good. I think we could also use:

#if APR_VERSION_AT_LEAST(1,6,0)
                stat = apr_sockaddr_info_copy(&duplr->bind_addr,
                                              lr->bind_addr, p);
#else
                stat = apr_sockaddr_info_get(&duplr->bind_addr, hostname,
                                             lr->bind_addr->family,
                                             port, 0, p);
#endif

to avoid a DNS resolution (and preserve multiple addresses for e.g. Listen <hostname>, copying gives every duplicate exactly the address its listener bound, with no lookup at all).

ap_duplicate_listeners() resolved each listener's hostname again with
apr_sockaddr_info_get(hostname, APR_UNSPEC, ...) to create the extra
per-bucket sockets, so a duplicate could bind a different address than
the original listener:

- for a wildcard "Listen <port>", the duplicated buckets came back as
  plain IPv4 sockets while the original was IPv6 dual-stack, leaving a
  single socket able to accept IPv6 connections;
- for a link-local "Listen [fe80::...%iface]", the scope was lost and
  the bind failed with EINVAL, so httpd did not start.

Copy each listener's bound address with apr_sockaddr_info_copy()
instead, as suggested by Yann, and keep a lookup with the listener's
family for APR < 1.6.

PR: 69804
@arturobernalg
arturobernalg force-pushed the fix/bz69804-listencbratio-ipv6-family branch from 9a3b3f6 to b783b44 Compare November 30, 2026 13:14
@arturobernalg

Copy link
Copy Markdown
Member Author

Thanks Yann, done. The copy also fixes a link-local "Listen [fe80::...%iface]": the new lookup lost the scope, so the duplicated listeners failed to bind (EINVAL) and httpd did not start. Test added.

@ylavic ylavic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants