Skip to content

Degrade gracefully when flock is unavailable on NFS-backed log volumes#1561

Open
zakame wants to merge 2 commits into
Difegue:devfrom
zakame:bugfix/rotatinglog-nfs-flock
Open

Degrade gracefully when flock is unavailable on NFS-backed log volumes#1561
zakame wants to merge 2 commits into
Difegue:devfrom
zakame:bugfix/rotatinglog-nfs-flock

Conversation

@zakame
Copy link
Copy Markdown

@zakame zakame commented May 16, 2026

Fixes #1556

Since #1406, RotatingLog dies on every append() when the log volume is NFS without a working lock manager (EBADF/ENOLCK from flock(2)), crashing Mojolicious workers on every log write.

Changes:

  • _try_flock(): wraps all flock() calls; on first EBADF/ENOLCK, sets a sticky flock_disabled flag, emits one warn() with remediation hints, and falls back to best-effort unlocked logging for that process
  • LRR_LOG_LOCK_DIRECTORY: env var to relocate the .lock file to a local path when the log volume is NFS
  • autoflush(1) on all handle-creation paths to avoid losing log lines on SIGKILL/OOMKill

Tests in tests/LANraragi/Utils/RotatingLog.t.

This is the alternative approach to #1559 — detection at the point of first flock() failure rather than a startup probe, which also handles the case where flock degrades mid-process. Happy to consolidate if you prefer one approach.

zakame added 2 commits May 16, 2026 16:41
Add _try_flock() to catch EBADF/ENOLCK on first failure, set a sticky
flock_disabled flag, and fall back to best-effort unlocked logging.
Also add LRR_LOG_LOCK_DIRECTORY env var and autoflush on all log handles.
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.

Logger crashes with "Failed to acquire shared log lock" on NFS-backed log volumes

1 participant