<div class="tw-paragraph"><p><span>Hi all,</span></p><p><span>I've been investigating an incident where DNS resolution stopped responding during sustained disk I/O. </span><span>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.</span></p><p data-pm-slice="1 1 []"><span>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.</span></p><p><span>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.</span></p><p><span>The incident occurred on Pi-hole FTL 6.9, which embeds a modified dnsmasq, rather than standalone upstream dnsmasq. </span><span>However, the relevant direct-file logging behaviour appears to originate in dnsmasq and I believe it may be worth improving upstream.</span></p><p><span>During a large file transfer to a ZFS pool, I observed:</span></p><ul><li><p><span>Incoming DNS requests reaching the resolver's UDP sockets, without corresponding responses.</span></p></li><li><p><span>Full UDP receive buffers and actively increasing kernel packet-drop counters.</span></p></li><li><p><span>FTL's main thread blocked in </span><code><span>write(fd=33, ..., 111)</span></code><span>, where FD 33 was </span><code><span>/var/log/pihole/pihole.log</span></code><span>.</span></p></li><li><p><span>A kernel stack through </span><code><span>zfs_write()</span></code><span> into </span><code><span>zfs_rangelock_enter_writer()</span></code><span> and later </span><code><span>dmu_tx_wait()</span></code><span>.</span></p></li><li><p><span>Normal DNS operation returning without restarting FTL when the unrelated file transfer was paused.</span></p></li></ul><p data-pm-slice="1 1 []"><span>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. </span></p><p><span>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.</span></p><p><span>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.</span></p><span>In </span><code><span>src/log.c</span></code><span>, the existing asynchronous syslog implementation already has bounded queueing, overflow accounting, nonblocking socket writes, and event-loop integration. However, direct file logging explicitly sets </span><code><span>max_logs = 0</span></code><span> and performs writes to a regular file in the caller's context. <a href="https://android.googlesource.com/platform/external/dnsmasq/%2B/68a974de72b5091ce608815a349daaeb05cdeab5/FAQ#438" target="_blank" rel="noopener" data-mce-href="https://android.googlesource.com/platform/external/dnsmasq/%2B/68a974de72b5091ce608815a349daaeb05cdeab5/FAQ#438">This FAQ</a> explains that </span><span>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. </span><span>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.</span><p><span>Would it make sense to extend the existing asynchronous logging mechanism to support direct file logging?</span></p><p data-pm-slice="1 1 []"><span>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.</span></p><p><span>An alternative could be an in-process ring buffer with a writer thread and a notification mechanism, although reusing the existing infrastructure seems preferable.</span></p><p><span>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.</span></p><p><span>I realize the implementation would need to account for log rotation, shutdown, forked workers, and the existing queue's backpressure behaviour.</span></p><p><span>Before attempting a patch, I'd appreciate feedback on:</span></p><ol start="1" data-spread="false"><li><p><span>Whether there are historical or architectural reasons why direct file logging doesn't use the asynchronous mechanism.</span></p></li><li><p><span>Whether reusing the existing queue and introducing a dedicated file writer would be an acceptable upstream direction.</span></p></li><li><p>Whether a smaller change could achieve the same goal: dropping log entries rather than DNS requests under heavy disk I/O.</p></li></ol><p><span>I haven't reproduced this against standalone upstream dnsmasq, so there may be FTL-specific interactions I haven't accounted for.</span></p><p><span>I'm happy to develop a standalone dnsmasq reproducer and work on a patch if the approach is reasonable.</span></p><p><span>Thanks!</span></p><br></div><div><br></div><div class="" id="typewire-signature-container"><table role="presentation" cellpadding="0" cellspacing="0" border="0" style="font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.35;color:#111;" class="mce-item-table">
        <tbody><tr>
                <td style="padding:0 16px 0 0;vertical-align:top;">
                        <img src="https://cordilleralabs.ca/images/cordillera_labs_logo_text_square.png" alt="Cordillera Labs" width="140" style="display:block;width:140px;height:auto;margin-top:2px;">
                </td>
                <td style="padding:0 0 0 16px;vertical-align:top;border-left:2px solid #e0e0e0;">
                        <div style="font-size:16px;font-weight:700;color:#111;letter-spacing:-0.2px;">Alex Fraser</div>
                        <div style="font-size:13px;font-weight:600;color:#444;margin-top:1px;">Cordillera Labs Ltd.</div>
                        <div style="font-size:12px;color:#888;margin-top:2px;">Scientific software development & consulting</div>
                        <div style="height:10px;border-bottom:1px solid #e8e8e8;margin-bottom:8px;"></div>
                        <div style="font-size:12px;color:#555;line-height:1.6;">
                                <span style="color:#999;">E  </span>
                                <a href="mailto:alexfraser@cordilleralabs.ca" style="color:#0b57d0;text-decoration:none;">alex@cordilleralabs.ca</a>
                                  
                                <span style="color:#999;">W  </span>
                                <a href="https://cordilleralabs.ca" style="color:#0b57d0;text-decoration:none;">cordilleralabs.ca</a>
                        </div>
                </td>
        </tr>
</tbody></table></div>