Skip to content

Upstream Zephyr: BUILD_ASSERT for CONFIG_ZVFS_POLL_MAX is off by one #50

Description

@mikeysklar

Not our bug. Recorded here so it is not lost. Do not file upstream without checking with Phil.

include/zephyr/net/dns_resolve.h:220-225:

#define DNS_DISPATCHER_MAX_POLL (DNS_RESOLVER_MAX_POLL + MDNS_MAX_POLL + LLMNR_MAX_POLL)

#if defined(CONFIG_ZVFS_POLL_MAX)
BUILD_ASSERT(CONFIG_ZVFS_POLL_MAX >= DNS_DISPATCHER_MAX_POLL,
	     "CONFIG_ZVFS_POLL_MAX must be larger than " STRINGIFY(DNS_DISPATCHER_MAX_POLL));
#endif

The runtime bound is one higher. sockets_service.c reserves ctx.events[0] for its own
eventfd and polls count + 1 entries, so the check at line 208 is
if ((count + 1) > ARRAY_SIZE(ctx.events)). When it fires the thread jumps to fail:, sets
SOCKET_SERVICE_THREAD_FAILED and returns, and sockets registered with the service are never
read. Both NET_ERRs explaining it are compiled out at the common NET_SOCKETS_LOG_LEVEL=0.

The stock configuration lands exactly on the boundary. DNS_RESOLVER=y plus
MDNS_RESPONDER=y, IPv4 and IPv6, one interface, DNS_RESOLVER_MAX_SERVERS=1 gives
DNS_DISPATCHER_MAX_POLL = 1 + 2 + 0 = 3, and ZVFS_POLL_MAX defaults to 3. The assert
passes on 3 >= 3 and the thread dies at runtime. Either feature alone is fine.

Fix is one character:

BUILD_ASSERT(CONFIG_ZVFS_POLL_MAX > DNS_DISPATCHER_MAX_POLL,

Even then the assert counts only the DNS services, while any other NET_SOCKET_SERVICE_*_DEFINE
in the image adds to the same array. The real invariant is the total across all registered
services plus one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingport:siwx917SiWx917 CircuitPython port

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions