Skip to content

Don't panic when writing to the log file fails - #1265

Open
ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-logger-io-panic
Open

ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-logger-io-panic

Conversation

@ajaysehwal

Copy link
Copy Markdown
Contributor

The file logger reopens the log file for each record and expects both the open and the write to succeed. Any I/O error (a full disk, a removed log directory, changed permissions) therefore panics in whatever thread is logging, which can be a background task holding locks. With panic = "abort" this kills the host process.

This prints the error to stderr and drops the record instead, as we already do when setting up the log file fails in Logger::new_fs_writer. The file is still reopened per record, so external log rotation keeps working.

Testing

Added log_file_write_errors_do_not_panic, which removes the log directory after creating the logger and then logs a line. It panics without this change and passes with it.

The file logger reopened the log file for each record and `expect`ed
both the open and the write to succeed. Any I/O error, e.g. a full disk
or a removed log directory, therefore panicked in whatever thread was
logging, which could be a background task holding locks.

Print the error to stderr instead and drop the record, as we already do
when setting up the log file fails.
@ldk-reviews-bot

ldk-reviews-bot commented Nov 26, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

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