Skip to content

Don't panic when background event processing fails - #1260

Open
ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-bp-failure-panic
Open

ajaysehwal wants to merge 1 commit into
lightningdevkit:mainfrom
ajaysehwal:fix-bp-failure-panic

Conversation

@ajaysehwal

Copy link
Copy Markdown
Contributor

Fixes the panic-on-background-processor-failure part of #381 (the "P0, easy" item in the discussion there).

Problem

If process_events_async returns an error (e.g. a persistence failure), the background processor task panicked:

  • With panic = "abort" (bindings, mobile) this aborts the host process.
  • Without it, only the task dies. The node keeps running and reports is_running, but nothing is persisted or handled anymore. A later Node::stop then hits panic!("Stopping event handling failed...") while holding the is_running write lock, which poisons the lock so every subsequent API call panics too.

Changes

  • The background processor task now returns its Result instead of panicking.
  • If it fails while the node is running, it logs the error, sends the stop signal to the other background tasks and disconnects all peers, so no further channel state changes can happen without persistence.
  • Runtime::wait_on_background_processor_task returns Error::PersistenceFailed for a failed or panicked task instead of panicking.
  • Node::stop marks the node as not running and returns that error. Node::start still just winds down on a failed startup and reports the startup error.

Not in this PR

  • Surfacing the failed state through the rest of the API (e.g. returning an error from other methods and status()), which needs a bigger design change.
  • A shutdown timeout still returns Ok, as before.

Testing

Added unit tests in runtime.rs for a clean exit, a failed task and a panicking task. cargo test --lib runtime:: passes. There is no end-to-end test with a failing store.

A failing background processor used to `panic!`, which aborted the host
process or, for embedders that unwind, left a node that kept running
without persisting anything. `Node::stop` then panicked again while
holding the `is_running` write lock, poisoning it for all later calls.

Have the background processor task return its result instead. On
failure it now logs, signals the other background tasks to stop and
disconnects all peers, so no further channel state changes happen.
`wait_on_background_processor_task` reports a failed or panicked task
as `Error::PersistenceFailed`, which `Node::stop` returns after marking
the node as not running.
@ldk-reviews-bot

ldk-reviews-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

I've assigned @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

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