Repository navigation
cln-plugin: do not panic when the log writer task is gone - #9732
Merged
Merged
Conversation
LoggingLayer::on_event forwarded events to the log writer task with sender.send(...).unwrap(). Once that task is gone -- the runtime is shutting down, or the task was dropped or panicked -- the receiver has been dropped, send returns Err(SendError(entry)) and the unwrap panics in whichever code emitted the log event. This usually showed up during node shutdown, after "Lost connection to the RPC socket." Take the entry back out of the SendError and write it to stderr instead: logging must never panic, and we must not drop the entry either. stderr and not stdout, since stdout is the JSON-RPC channel to lightningd. Add a unit test that drives the LoggingLayer with a dropped receiver via a local subscriber; it panics without the fallback. Changelog-Fixed: cln-plugin: a plugin no longer panics when it logs after its log writer task has exited (e.g., during shutdown); the message is written to stderr instead.
daywalker90
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LoggingLayer::on_eventpanicked if the log writer task had already exited (runtime shutting down, or the task dropped or panicked): the receiver is gone,sendreturnsErr(SendError), and the.unwrap()blew up in whatever code happened to log — usually during node shutdown, afterLost connection to the RPC socket.The fallback goes to stderr — stdout is the JSON-RPC channel to lightningd — and the entry is never silently dropped.
Evidence
test_logging_layer_with_dropped_writer(local subscriber viawith_default, receiver pre-dropped) fails withcalled \Result::unwrap()` on an `Err` value: SendError— the exact production backtrace from the 0.1.9 report. **After:**cargo test -p cln-plugin:49 passed; 0 failed;cargo clippy -p cln-plugin` flags nothing on the changed lines.Merge Danger
Door: two-way — pure behavioral fallback, trivially revertable.
Blast Radius: plugin log output during shutdown only.