[Dnsmasq-discuss] bind-dynamic race condition
Francesco
francesco.montorsi at gmail.com
Wed Nov 4 10:09:49 UTC 2026
My bad, I see the attachment has been scrubbed by the mailing list rules.
Let me retry:
diff --git a/tests/bind-dynamic-veth-repro/Dockerfile
b/tests/bind-dynamic-veth-repro/Dockerfile
new file mode 100644
index 0000000000000000000000000000000000000000..f074e433fde94a204a6eb0f6a79fee5336a69e1c
--- /dev/null
+++ b/tests/bind-dynamic-veth-repro/Dockerfile
@@ -0,0 +1,13 @@
+FROM debian:bookworm-slim AS build
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends build-essential
ca-certificates git pkg-config \
+ && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /src
+COPY . .
+RUN make -j2
+
+FROM debian:bookworm-slim
+COPY --from=build /src/src/dnsmasq /usr/sbin/dnsmasq
+ENTRYPOINT ["/usr/sbin/dnsmasq"]
diff --git a/tests/bind-dynamic-veth-repro/README.md
b/tests/bind-dynamic-veth-repro/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..a977247b63373e5fb70309a9e1fd07d75b858f84
--- /dev/null
+++ b/tests/bind-dynamic-veth-repro/README.md
@@ -0,0 +1,44 @@
+# `bind-dynamic` Docker veth churn reproducer
+
+This harness checks whether repeated creation and removal of Docker container
+endpoints can make dnsmasq lose its IPv4 listeners while running with
+`bind-dynamic`.
+
+Run it only on a disposable Linux Docker host: the dnsmasq test container uses
+host networking so it receives the host's rtnetlink address notifications. It
+binds only `127.0.0.1:1053`, avoiding the normal DNS port. Short-lived helper
+containers use a dedicated Compose bridge with IPv6 enabled; their veth
+endpoints and addresses are created and removed on the host. The script checks
+the DNS listener once while each helper endpoint is present and again after it
+is deleted.
+
+```sh
+./tests/bind-dynamic-veth-repro/run.sh
+```
+
+The default run performs 200 endpoint cycles with a one-second pause between
+cycles. Override `ITERATIONS` or `INTERVAL_SECONDS` to change the run length or
+pace. The script checks for both UDP and TCP listeners. On failure it records
+the iteration, phase, and timestamp in
`/tmp/dnsmasq-bind-dynamic-veth-repro.log`
+and prints the listener state and dnsmasq logs. Compose resources are removed
+on exit.
+
+The current dnsmasq Linux code subscribes to address notifications and queues
+`EVENT_NEWADDR` for `RTM_NEWADDR` and `RTM_DELADDR`; it does not subscribe to
+`RTM_NEWLINK`. This harness therefore exercises veth address churn, rather
+than link events alone.
+
+A passing run does not rule out a rare race. Increase `ITERATIONS` and repeat
+on the same kernel/Docker combination where the failure was observed.
+
+
+## Observed result
+
+On 2026-11-03, this harness reproduced the failure twice on Linux
+`7.2.10-200.fc44.x86_64` with Docker Engine `29.9.0`. The first run failed at
+iteration 11; after adding the build version label, a second run failed at
+iteration 40. Both failures occurred after deleting the helper endpoint. `ss`
+showed only the IPv6 listener on `::1:1053`, and dnsmasq logged
+`stopped listening on lo(#1): 127.0.0.1 port 1053`. The versioned run used
+source checkout `v2.93-44-g10fbc39`. The Compose project and its network were
+removed by the runner after each failure.
diff --git a/tests/bind-dynamic-veth-repro/compose.yaml
b/tests/bind-dynamic-veth-repro/compose.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..a7b7c750cadb9b934bfc2408f7a922ff62e4d56c
--- /dev/null
+++ b/tests/bind-dynamic-veth-repro/compose.yaml
@@ -0,0 +1,23 @@
+services:
+ dnsmasq:
+ build:
+ context: ../..
+ dockerfile: tests/bind-dynamic-veth-repro/Dockerfile
+ network_mode: host
+ command: ["--keep-in-foreground", "--conf-file=/etc/dnsmasq.conf"]
+ volumes:
+ - ./dnsmasq.conf:/etc/dnsmasq.conf:ro
+
+ churn:
+ image: alpine:3.20
+ command: ["sh", "-c", "sleep 2"]
+ networks:
+ - churn
+
+networks:
+ churn:
+ driver: bridge
+ enable_ipv6: true
+ ipam:
+ config:
+ - subnet: fd42:53:1::/64
diff --git a/tests/bind-dynamic-veth-repro/dnsmasq.conf
b/tests/bind-dynamic-veth-repro/dnsmasq.conf
new file mode 100644
index 0000000000000000000000000000000000000000..6d2ccb2eec20805be84bd31484d068b87b6606ab
--- /dev/null
+++ b/tests/bind-dynamic-veth-repro/dnsmasq.conf
@@ -0,0 +1,9 @@
+no-daemon
+log-facility=-
+log-debug
+port=1053
+no-resolv
+no-hosts
+interface=lo
+listen-address=127.0.0.1
+bind-dynamic
diff --git a/tests/bind-dynamic-veth-repro/run.sh
b/tests/bind-dynamic-veth-repro/run.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3c84d3167021a9e77757100a64eba26a71be1725
--- /dev/null
+++ b/tests/bind-dynamic-veth-repro/run.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+set -eu
+
+repro_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+compose_file="$repro_dir/compose.yaml"
+iterations=${ITERATIONS:-200}
+interval=${INTERVAL_SECONDS:-1}
+result_log=${RESULT_LOG:-/tmp/dnsmasq-bind-dynamic-veth-repro.log}
+helper_id=
+
+compose() {
+ docker compose -f "$compose_file" "$@"
+}
+
+cleanup() {
+ if [ -n "$helper_id" ]; then
+ docker rm -f "$helper_id" >/dev/null 2>&1 || true
+ fi
+ compose down --remove-orphans >/dev/null 2>&1 || true
+}
+trap cleanup EXIT HUP INT TERM
+
+if ! command -v ss >/dev/null 2>&1; then
+ echo "ss (iproute2) is required on the Docker host" >&2
+ exit 2
+fi
+
+compose build dnsmasq
+compose up -d dnsmasq
+sleep 2
+
+check_listener() {
+ udp=$(ss -H -lun 'sport = :1053' | awk '$4 == "127.0.0.1:1053" {
found=1 } END { print found+0 }')
+ tcp=$(ss -H -ltn 'sport = :1053' | awk '$4 == "127.0.0.1:1053" {
found=1 } END { print found+0 }')
+ [ "$udp" -eq 1 ] && [ "$tcp" -eq 1 ]
+}
+
+fail() {
+ printf '%s FAIL iteration=%s phase=%s: IPv4 UDP/TCP listener
disappeared\n' "$(date --iso-8601=seconds)" "$iteration" "$1" | tee -a
"$result_log" >&2
+ ss -H -lnptu 'sport = :1053' >&2 || true
+ compose logs dnsmasq >&2
+ exit 1
+}
+
+if ! check_listener; then
+ iteration=0
+ fail startup
+fi
+
+iteration=1
+while [ "$iteration" -le "$iterations" ]; do
+ helper_id=$(compose run -d --no-deps churn)
+ sleep 0.2
+ check_listener || fail create
+
+ docker wait "$helper_id" >/dev/null
+ docker rm "$helper_id" >/dev/null
+ helper_id=
+ check_listener || fail delete
+
+ if [ $((iteration % 25)) -eq 0 ]; then
+ printf '%s OK iterations=%s\n' "$(date --iso-8601=seconds)"
"$iteration"
+ fi
+ iteration=$((iteration + 1))
+ sleep "$interval"
+done
+
+printf '%s PASS iterations=%s listener=127.0.0.1:1053/udp,tcp\n'
"$(date --iso-8601=seconds)" "$iterations" | tee -a "$result_log"
Il giorno mer 4 nov 2026 alle ore 11:08 Francesco
<francesco.montorsi at gmail.com> ha scritto:
>
> Hi,
> Looking at the mailing list I see that the standard way to go is
> attach a patch to the email, so there we go.
> This patch allows you to reproduce, in a few seconds/minutes the race
> condition I mentioned in my previous email.
>
> I might try to propose a fix if there is interest!
>
> Thanks,
> Francesco
>
> Il giorno mar 3 nov 2026 alle ore 14:55 Francesco
> <francesco.montorsi at gmail.com> ha scritto:
> >
> > Hi all,
> >
> > First of all thanks for developing and maintaining dnsmasq, it's really useful and I'm the maintainer of an addon that integrates it with HomeAssistant (https://github.com/f18m/ha-addon-dnsmasq-dhcp).
> >
> > I recently started using the "bind-dynamic" feature and I have definitively isolated a bug in dnsmasq: I can reproduce an intermittent issue with dnsmasq 2.93-44-g10fbc39 on Linux using bind-dynamic. I created an isolated test to reproduce it, based on docker (compose).
> >
> > What happens is that after repeated creation and removal of Docker bridge container endpoints, dnsmasq stops listening on 127.0.0.1 over both UDP and TCP, while the IPv6 listener on ::1 remains. Its log reports:
> >
> > stopped listening on lo(#1): 127.0.0.1 port 1053
> >
> > The reproducer uses dnsmasq in host networking, bound only to 127.0.0.1:1053, and repeatedly creates/removes short-lived containers on an IPv6-enabled bridge. It reproduced after 11 and 40 cycles on Linux 7.2.10-200.fc44.x86_64 with Docker Engine 29.9.0. I can provide the minimal Docker Compose reproducer.
> >
> > I suspect there is a race condition somewhere related to the bind-dynamic implementation.
> >
> > What is the best way to share the test that reproduces this issue with you?
> >
> > I didn't find any bug tracker and although I git cloned the source, I'm not sure in which format you prefer to receive the test that reproduces the bug... should I send a .patch file?
> >
> > Thanks,
> >
> > Francesco Montorsi
More information about the Dnsmasq-discuss
mailing list