Skip to content

cln-plugin: do not panic when the log writer task is gone - #9732

Merged
cdecker merged 2 commits into
masterfrom
2026m11-plugin-log-senderror
Nov 12, 2026
Merged

cdecker merged 2 commits into
masterfrom
2026m11-plugin-log-senderror

Conversation

@cdecker

@cdecker cdecker commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

LoggingLayer::on_event panicked if the log writer task had already exited (runtime shutting down, or the task dropped or panicked): the receiver is gone, send returns Err(SendError), and the .unwrap() blew up in whatever code happened to log — usually during node shutdown, after Lost connection to the RPC socket.

 on_event
-  sender.send(entry).unwrap()   # panics once the writer task is gone
+  if let Err(err) = sender.send(entry)
+      eprintln!("{:?}: {}", err.0.level, err.0.message)  # stderr, never stdout

The fallback goes to stderr — stdout is the JSON-RPC channel to lightningd — and the entry is never silently dropped.

Evidence

  • Before: new test test_logging_layer_with_dropped_writer (local subscriber via with_default, receiver pre-dropped) fails with called \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.

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.
@cdecker
cdecker merged commit 8661ffa into master Nov 12, 2026
@cdecker
cdecker deleted the 2026m11-plugin-log-senderror branch November 12, 2026 17:23
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