Repository navigation
Don't panic when background event processing fails - #1260
ajaysehwal wants to merge 2 commits into
Conversation
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.
|
I've assigned @tnull as a reviewer! |
|
Field report: this failure mode cost a production node all of its channels We run ldk-node 0.6.1 (lightning 0.1.4, lightning-background-processor 0.1.0) Timeline (UTC, one day):
No funds were lost, but one transient |
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. From the open upstream PR. Its one conflict, after lightningdevkit#1229, was Runtime's fields: the background processor task takes upstream's Result type, and lightningdevkit#1229's monitor_persistence_cancellation_token stays. (cherry picked from commit a3fff85) Upstream-PR: lightningdevkit#1260
Previously a failed background processor stopped all background tasks, including chain syncing and transaction broadcasting, so the node no longer reacted to the chain until restarted. Only cut off peers instead, which is what keeps channel state from changing while the `ChannelManager` can't be persisted. To this end, `ConnectionManager` can now refuse connections at runtime, which also covers reconnects, LSP discovery and `Node::connect`, and the listener drops inbound connections while connections are disabled.
Thanks a lot for the detailed report, this is exactly the failure mode this PR is about. With the latest push, a failed background processor no longer panics. Instead the node disconnects all peers and refuses new connections (inbound, reconnects, |
|
@tnull Updated after the field report above. The second commit keeps chain sync and broadcasting running on a background processor failure and only cuts off peers, via a runtime switch on the existing Two questions before I go further:
|
Fixes the panic-on-background-processor-failure part of #381 (the "P0, easy" item in the discussion there).
Problem
If
process_events_asyncreturns an error (e.g. a persistence failure), the background processor task panicked:panic = "abort"(bindings, mobile) this aborts the host process.is_running, but theChannelManageris never persisted again and no events are handled. Peers stay connected and keep applying channel updates, so the persistedChannelManagerfalls further behind theChannelMonitors. On restart LDK then force-closes those channels as stale. A laterNode::stopalso hitspanic!("Stopping event handling failed...")while holding theis_runningwrite lock, which poisons the lock so every subsequent API call panics too.The field report below shows the second case in production: a single transient
EMFILEon oneChannelManagerwrite led to seven force closes.Changes
Resultinstead of panicking.Node::connect). Chain syncing and transaction broadcasting keep running, so the node still reacts to on-chain events until it is restarted.ConnectionManagercan now refuse connections at runtime, reusing the existingdisable_lightning_connectionscheck.Runtime::wait_on_background_processor_taskreturnsError::PersistenceFailedfor a failed or panicked task instead of panicking.Node::stopmarks the node as not running and returns that error.Node::startstill just winds down on a failed startup and reports the startup error.Not in this PR
is_runningstaystrue, only an error is logged). This touches the public API; see the question below.Ok, as before.Testing
Added unit tests in
runtime.rsfor a clean exit, a failed task and a panicking task.cargo test --libpasses. There is no end-to-end test with a store that starts failing while the node runs.