Skip to content

syslog: fix message-loss bug and blocking-DNS retry storm, cache hostname - #31

Merged
KrX3D merged 1 commit into
syslogfrom
fix/syslog-review-bugs
Sep 16, 2026
Merged

KrX3D merged 1 commit into
syslogfrom
fix/syslog-review-bugs

Conversation

@KrX3D

@KrX3D KrX3D commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up review of the syslog feature (wled00/syslog.cpp/syslog.h, after #3/#18/#22), looking for anything left. Found and fixed two real bugs plus one efficiency issue:

  • A real log line could be silently dropped instead of just the intended artifact. flushBuffer()'s "skip pure #015 artifact" filter is an exact match (_bufferIndex == 4), but write()'s equivalent check was a prefix match (size >= 4, only checking the first 4 bytes). Any genuine debug line longer than 4 bytes that happened to start with those same 4 characters passed flushBuffer() untouched (since it isn't exactly 4 bytes) but was then fully discarded by write(). Made both checks consistent (exact match only).
  • Blocking DNS lookups could repeat on every single log line with no backoff. resolveHostname() re-runs a blocking hostByName() call whenever resolution hasn't succeeded yet, and this sits on the hot path for the entire firmware's debug output (DEBUGOUT=Syslog). With a misconfigured or temporarily unreachable syslog host, every buffered log line paid the full blocking DNS timeout (up to 750ms on ESP8266, uncapped on ESP32/Ethernet) — risking main-loop stalls or watchdog resets under frequent debug logging. Added a 10-second backoff between retry attempts, with a separate "has attempted" flag so the very first resolution attempt at boot still happens immediately.
  • Unnecessary heap churn on every packet send. write() allocated and cleaned a fresh String from serverDescription on every single UDP packet, even though it only changes when the user edits it in settings. Cached it, mirroring the existing syslogHostIP caching pattern already used for the host.

Test plan

  • Static review only in this session (no PlatformIO toolchain available to build/flash here).
  • Recommend testing on real hardware: point syslog at an unreachable host with WLED_DEBUG on and confirm no main-loop stalls; send a debug line starting with #015 but longer than 4 bytes and confirm it now reaches the syslog server.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J6bJtispewBKR2dXBcNWpw


Generated by Claude Code

…name

- write()'s "#15" artifact filter used a prefix match (size>=4, first 4
  bytes) while flushBuffer()'s equivalent check is an exact match
  (size==4). Any real log line longer than 4 bytes that happened to start
  with "#15" passed flushBuffer() untouched but was then silently
  dropped entirely by write() - losing real diagnostic content instead of
  just the intended artifact line. Made both checks consistent (exact
  match only).
- resolveHostname() re-ran a blocking hostByName() DNS lookup on every
  single syslog flush whenever resolution hadn't yet succeeded, with no
  backoff. Since this runs on the hot path for the entire firmware's
  debug output (DEBUGOUT=Syslog), a misconfigured/unreachable syslog host
  meant every buffered log line paid the full blocking DNS timeout,
  risking main-loop stalls/watchdog resets under frequent logging. Added
  a 10s backoff between retry attempts (an immediate first attempt is
  still guaranteed via a separate "has attempted" flag, so this doesn't
  delay normal startup resolution).
- write() re-allocated and cleaned a new String from serverDescription on
  every single packet send. Cached it (mirroring the existing syslogHostIP
  caching pattern) and only recompute when serverDescription changes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01J6bJtispewBKR2dXBcNWpw
@KrX3D
KrX3D merged commit 7c0a772 into syslog Sep 16, 2026
24 checks passed
@KrX3D
KrX3D deleted the fix/syslog-review-bugs branch September 16, 2026 12:41
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.

2 participants