Skip to content

cln-plugin: fix missed-wakeup deadlock in Plugin::join and Plugin::shutdown - #9757

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-join-shutdown
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-join-shutdown

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

Plugin::wait_handle used a tokio::sync::broadcast::Sender<()> with
its initial receiver immediately dropped. If PluginDriver::run exited
or Plugin::shutdown() was called before the caller reached
Plugin::join(), broadcast::Sender::send(()) failed with zero
receivers and dropped the signal; subsequent Plugin::join() calls then
hung indefinitely because Plugin itself still held the Sender. In
addition, PluginDriver::run never observed wait_handle, so
Plugin::shutdown() did not stop the driver loop.

Replace the broadcast channel with a tokio::sync::watch::Sender<bool>
(updated via send_replace(true)), drop a guard on driver exit so the
state is always flipped even on unwind, and select on the watch channel
in PluginDriver::run so shutdown() stops the driver loop cleanly.

Add unit tests covering join() after driver exit, shutdown() before
join(), and shutdown() waking a waiting join().

Changelog-Fixed: cln-plugin: fix missed-wakeup deadlock in Plugin::join() and make Plugin::shutdown() reliably stop the driver loop.

…:shutdown`

`Plugin::wait_handle` used a `tokio::sync::broadcast::Sender<()>` with
its initial receiver immediately dropped. If `PluginDriver::run` exited
or `Plugin::shutdown()` was called before the caller reached
`Plugin::join()`, `broadcast::Sender::send(())` failed with zero
receivers and dropped the signal; subsequent `Plugin::join()` calls then
hung indefinitely because `Plugin` itself still held the `Sender`. In
addition, `PluginDriver::run` never observed `wait_handle`, so
`Plugin::shutdown()` did not stop the driver loop.

Replace the broadcast channel with a `tokio::sync::watch::Sender<bool>`
(updated via `send_replace(true)`), drop a guard on driver exit so the
state is always flipped even on unwind, and select on the watch channel
in `PluginDriver::run` so `shutdown()` stops the driver loop cleanly.

Add unit tests covering `join()` after driver exit, `shutdown()` before
`join()`, and `shutdown()` waking a waiting `join()`.

Changelog-Fixed: cln-plugin: fix missed-wakeup deadlock in `Plugin::join()` and make `Plugin::shutdown()` reliably stop the driver loop.
@daywalker90
daywalker90 requested a review from cdecker as a code owner November 24, 2026 12:01

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