Skip to content

cln-plugin: catch synchronous panics in callback invocation - #9760

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-sync-callback-panic
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-sync-callback-panic

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

PluginDriver::dispatch_one invoked callback(plugin.clone(), params) directly on the driver task before tokio::spawn and outside FutureExt::catch_unwind. If a hook, RPC, or notification closure panicked synchronously before returning its Future, the panic unwound PluginDriver::run and killed the entire plugin without sending a hook fallback or JSON-RPC error response.

Wrap all four callback invocations (hooks, RPC/setconfig, wildcard notifications, and topic notifications) in
std::panic::catch_unwind(std::panic::AssertUnwindSafe(...)) so synchronous panics follow the same fallback, error-reply, and logging paths as panics inside the returned Future.

Add a regression test verifying that synchronous panics in hook, RPC, wildcard notification, and topic notification callbacks return the expected fallback/error responses and leave the driver alive for subsequent requests.

Changelog-Fixed: cln-plugin: catch synchronous panics in hook, RPC, and notification callbacks instead of crashing the plugin driver loop.

`PluginDriver::dispatch_one` invoked `callback(plugin.clone(), params)`
directly on the driver task before `tokio::spawn` and outside
`FutureExt::catch_unwind`. If a hook, RPC, or notification closure
panicked synchronously before returning its `Future`, the panic unwound
`PluginDriver::run` and killed the entire plugin without sending a hook
fallback or JSON-RPC error response.

Wrap all four callback invocations (hooks, RPC/`setconfig`, wildcard
notifications, and topic notifications) in
`std::panic::catch_unwind(std::panic::AssertUnwindSafe(...))` so
synchronous panics follow the same fallback, error-reply, and logging
paths as panics inside the returned `Future`.

Add a regression test verifying that synchronous panics in hook, RPC,
wildcard notification, and topic notification callbacks return the
expected fallback/error responses and leave the driver alive for
subsequent requests.

Changelog-Fixed: cln-plugin: catch synchronous panics in hook, RPC, and notification callbacks instead of crashing the plugin driver loop.
@daywalker90
daywalker90 requested a review from cdecker as a code owner November 24, 2026 13:54

This branch has not been deployed

No deployments
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.

1 participant