Skip to content

cln-plugin: do not drop JsonRpc::Error replies on select! cancellation - #9759

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-error-reply-drop
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-error-reply-drop

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

PluginDriver::run polled self.dispatch_one(&mut input, &self.plugin) inside tokio::select! alongside receiver.recv(). When JsonRpc::Error arrived, dispatch_one awaited
plugin.sender.send(rpc_error).await on the bounded mpsc::channel(4). If that channel was full, receiver.recv() won the select! and cancelled dispatch_one, silently dropping the -32700 error reply and leaving lightningd waiting indefinitely for that request id.

Poll input.next() directly in tokio::select! (which is cancel-safe), make message dispatching synchronous in PluginDriver::dispatch_message returning an optional immediate reply, and write JsonRpc::Error replies directly to output in PluginDriver::run (also avoiding self-deadlocking on a full mpsc channel).

Add a regression test saturating the bounded mpsc channel while sending malformed JSON frames and verifying every -32700 error reply is delivered.

Changelog-Fixed: cln-plugin: prevent JsonRpc::Error replies from being silently dropped when the internal response channel is full.

…ation

`PluginDriver::run` polled `self.dispatch_one(&mut input, &self.plugin)`
inside `tokio::select!` alongside `receiver.recv()`. When
`JsonRpc::Error` arrived, `dispatch_one` awaited
`plugin.sender.send(rpc_error).await` on the bounded `mpsc::channel(4)`.
If that channel was full, `receiver.recv()` won the `select!` and
cancelled `dispatch_one`, silently dropping the `-32700` error reply
and leaving `lightningd` waiting indefinitely for that request `id`.

Poll `input.next()` directly in `tokio::select!` (which is cancel-safe),
make message dispatching synchronous in `PluginDriver::dispatch_message`
returning an optional immediate reply, and write `JsonRpc::Error`
replies directly to `output` in `PluginDriver::run` (also avoiding
self-deadlocking on a full `mpsc` channel).

Add a regression test saturating the bounded `mpsc` channel while
sending malformed JSON frames and verifying every `-32700` error reply
is delivered.

Changelog-Fixed: cln-plugin: prevent `JsonRpc::Error` replies from being silently dropped when the internal response channel is full.
@daywalker90
daywalker90 requested a review from cdecker as a code owner November 24, 2026 13:04

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