[Dnsmasq-discuss] Extending asynchronous logging to direct file output
Alex Fraser
alexfraser at cordilleralabs.ca
Sat Nov 21 07:22:56 UTC 2026
Hi all,
I've been investigating an incident where DNS resolution stopped responding
during sustained disk I/O. I traced a stall in the resolver's main thread to
a direct log-file write, while incoming DNS queries were being dropped.
After diagnosing and remedying my issue, I also see a potential opportunity
to improve dnsmasq's log handling.
Full disclosure: the investigation was substantially assisted by Codex, as
it involved quite the yak shave. What began as intermittent connectivity on
my smart TV led through failing Wi-Fi mesh networking, a potentially faulty
Ethernet connection, and finally to Pi-hole becoming unresponsive during a
large file transfer to my TrueNAS server.
Needless to say, there were several independent problems in the chain of my
local network failures today and I certainly would not have had the time to
trace it all manually. The remainder of the email was also drafted with
assistance from Codex with my own editing for clarity.
The incident occurred on Pi-hole FTL 6.9, which embeds a modified dnsmasq,
rather than standalone upstream dnsmasq. However, the relevant direct-file
logging behaviour appears to originate in dnsmasq and I believe it may be
worth improving upstream.
During a large file transfer to a ZFS pool, I observed:
Incoming DNS requests reaching the resolver's UDP sockets, without
corresponding responses.
Full UDP receive buffers and actively increasing kernel packet-drop
counters.
FTL's main thread blocked in write(fd=33, ..., 111), where FD 33 was
/var/log/pihole/pihole.log.
A kernel stack through zfs_write() into zfs_rangelock_enter_writer() and
later dmu_tx_wait().
Normal DNS operation returning without restarting FTL when the unrelated
file transfer was paused.
The underlying storage problem is reasonably well understood. One member of
the ZFS mirror is an SMR hard drive that exhibited write latencies of
hundreds of milliseconds to several seconds during sustained transfers,
compared with a few milliseconds on its CMR mirror partner.
After pausing the transfer, disk latency returned to normal, system-wide I/O
pressure dropped dramatically, and Pi-hole resumed answering queries. I
believe the write cache was full, as this is a typical failure mode of
shingled drives under heavy sustained writes. I intend to move Pi-hole's
storage to a separate SSD pool.
I'm aware that the SMR drive is poorly suited to sustained write workloads.
However, although I've identified and mitigated the immediate problem, I
have to wonder if diagnostic logging needs to be in the critical path of
serving DNS responses at all.
In src/log.c, the existing asynchronous syslog implementation already has
bounded queueing, overflow accounting, nonblocking socket writes, and
event-loop integration. However, direct file logging explicitly sets
max_logs = 0 and performs writes to a regular file in the caller's context.
This FAQ explains that asynchronous syslog was introduced to avoid a
particular DNS/syslog deadlock. Direct file logging doesn't have that
circular dependency, but it can still stall DNS processing if the filesystem
blocks. It seems to me that the same general principle could apply: if
diagnostic logging cannot keep up, it would be preferable to drop log
records rather than delay or drop DNS responses.
Would it make sense to extend the existing asynchronous logging mechanism to
support direct file logging?
My initial thought is to retain the existing bounded queue, formatting, and
nonblocking producer mechanism, but direct file-log messages through a
nonblocking IPC endpoint to a dedicated writer responsible for filesystem
operations.
An alternative could be an in-process ring buffer with a writer thread and a
notification mechanism, although reusing the existing infrastructure seems
preferable.
In either case, a blocked filesystem write would not directly stall the
DNS-serving thread. If the queue filled, log records could be dropped and
counted, with a summary emitted once the writer recovered.
I realize the implementation would need to account for log rotation,
shutdown, forked workers, and the existing queue's backpressure behaviour.
Before attempting a patch, I'd appreciate feedback on:
Whether there are historical or architectural reasons why direct file
logging doesn't use the asynchronous mechanism.
Whether reusing the existing queue and introducing a dedicated file writer
would be an acceptable upstream direction.
Whether a smaller change could achieve the same goal: dropping log entries
rather than DNS requests under heavy disk I/O.
I haven't reproduced this against standalone upstream dnsmasq, so there may
be FTL-specific interactions I haven't accounted for.
I'm happy to develop a standalone dnsmasq reproducer and work on a patch if
the approach is reasonable.
Thanks!
Alex Fraser
Cordillera Labs Ltd.
Scientific software development & consulting
E alex at cordilleralabs.ca W cordilleralabs.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20261121/875e9edd/attachment-0001.htm>
More information about the Dnsmasq-discuss
mailing list