Repository navigation
fix: return errors on rust panics instead of aborting - #145
Conversation
Mobile builds of release-smaller now unwind, so UniFFI turns a panic into an error. A panic hook then stops every node built before it: no further event processing or ChannelManager persistence, no background tasks, no peers. Verified: cargo test --features uniffi --lib and --test panic_test; cargo check with and without uniffi
Verified: python3 scripts/check_panic_unwind.py; actionlint
stop() and Drop survive locks a panic poisoned, and a panic during start() is caught by the guard. Verified: cargo test --features uniffi --lib and --test panic_test; cargo check with and without uniffi
Verified: python3 scripts/check_panic_unwind.py
A variable `--profile`, a profile missing from `Cargo.toml`, an `inherits` cycle and an included Cargo config now fail the check. The job gets a timeout and keeps no token on disk. Verified: panic check on the clean tree and with each new case added, actionlint
A quoted or escaped `panic` setting, a quoted `--target` and a mobile build with no profile flag now fail the check, and shell comments are ignored. Verified: panic check on the clean tree and with each new case added
Quoted strings are skipped when comments are dropped, and a quoted `--release` is read. Verified: panic check on the clean tree and with each new case added
Dropping them could hide a mobile build. Only full-line comments are skipped again, and a `--release` next to a redirect is read. Verified: panic check on the clean tree and with each case added
A flag after a `#` no longer counts, and a comment line ending in a backslash no longer swallows the build after it. Verified: panic check on the clean tree and with each case added
|
Cancelled a full-suite run of this branch: two Linux jobs hung in |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4b39c297b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
talosmachina
left a comment
There was a problem hiding this comment.
Switches the mobile release-smaller profile to panic = 'unwind' and adds a process-wide panic hook that fail-stops every node built before a panic: the background processor is aborted without its final persist, tasks are cancelled, peers are disconnected, and start returns PersistenceFailed until a new Node is built.
No findings. Reviewed at c4b39c2, full tier, static only.
Build skipped: the PR's code was not built or run here (my run gate could not confirm the author's write access through this token and fails closed). The Rust suite (rust.yml) runs only on workflow_dispatch, so on this head CI ran only mobile-builds-unwind (green). The author's linked branch runs are the only execution evidence.
Merge confidence: 4/5, held at 4 because neither I nor CI on this head ran cargo test --features uniffi or panic_test.rs.
What I checked
- Lifecycle ordering: the guard is spawned first in
start_serviceswith the new generation, andstopbumps the generation before tearing down, so a guard firing duringstopreturns instead of racing the shutdown. The guard sits in the cancellable task set, sostopaborts it. - Startup panic window: a panic before the processor exists is covered by the post-spawn
panic::count()check that aborts the processor. stopafter a guard fail-stop: the processor is aborted, not signalled, so the finalChannelManagerpersist is skipped. The cancelled join maps toPersistenceFailed, the VSS live mark is cleared, and the nextstartis refused by the count check. This matchespanic_test.rs.- Poisoned
lifecycle_lock:lock_lifecyclerecovers viaPoisonError::into_inner, soDropstill runsstop. The runtime's own locks already usedmutex_lockwith the same recovery. disconnect_peerscatching a panic still bumps the hook count. That only happens after a first panic has already fail-stopped the node, so it changes nothing.- Profiles:
check_panic_unwind.pyresolvesrelease-smallerthroughinherits, and every mobilecargo build --targetline in the Android and Swift scripts uses it.releaseanddevstayabort. Tests ignore the profile's panic setting, sopanic_test.rsunwinds undercargo test. - Ruled out: the hook seeing panics from other Rust libraries in the app. Each staticlib/cdylib links its own
stdand therefore its own hook. The process-wide scope inside ldk-node is stated in the PR body as accepted residual risk.
The background processor now drops itself on a panic, instead of relying on the guard or `stop` to abort it, which left it persisting while `stop` waited. It ends without reporting a failure, so the guard still disconnects the peers. Verified: cargo build with and without uniffi, panic_test three times, library tests with uniffi
|
Force-pushed the throwaway test branch to rerun the suite on 04873ce, since the description's runs predate that change: https://github.com/synonymdev/ldk-node/actions/runs/46225871001 |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 04873ce.
2 actionable findings — resolve or provide an evidence-backed rebuttal.
Channel-changing calls still reach ChannelManager after the new fail-stop, and Node::stop can return success when a panic arrives while it waits for the final event-processor flush.
The resolved comment Keep panic monitoring active until the processor has stopped is addressed on this commit: end_on_panic drops the background processor when a panic is recorded, including during stop. The success result above is the remaining gap on that path. No matching open issue turned up for either mechanism.
Validation: python3 scripts/check_panic_unwind.py at this commit exits 0 and reports panic = unwind for the Android and Swift mobile build scripts. This review did not run cargo test or tests/panic_test.rs. The author reports a suite rerun in run 46225871001.
Suggested additional test cases
cargo test --features uniffi --test panic_test, using the two-node bitcoind setup inpanic_stops_the_node_until_it_is_rebuiltafter a channel is open. Snapshot the node's sqlite channel-monitor bytes, panic on another thread, wait untilstatus().is_runningis false, then callforce_close_channeland, with a known claimable payment,bolt11_payment().claim_for_hash. Both should returnPersistenceFailed, and the monitor bytes should match the snapshot.- While
Node::stopis insidewait_on_background_processor_task, panic on another thread.stopshould returnPersistenceFailed.
Findings
- [HIGH] Reject channel updates after a panic fail-stop — inline at
src/lib.rs:877. - [MEDIUM] Return PersistenceFailed if a panic hits during stop's final flush — inline at
src/lib.rs:968.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Calls that change channel state now return PersistenceFailed once a panic occurred since the node was built, and stop reads the panic count again after waiting for the background processor. Verified: cargo build with and without uniffi; cargo test --features uniffi --lib and --test panic_test
Verified: check_panic_unwind.py on the build scripts and on temp copies with cargo b and cargo rustc builds
Verified: cargo test --features uniffi --test panic_test, which fails without the re-read of the panic count
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 04873ce, including affected code paths, at 5471475. Baseline: previous review. Inherited coverage is the mobile release-smaller unwind profile and panic-unwind workflow, the process-wide panic hook and fail-stop, and the changelog contract.
No new actionable code findings.
The new guards return PersistenceFailed before close, force-close, splice, channel-config updates, event_handled, claim_for_hash, and fail_for_hash use their arguments. stop reads the panic count again after waiting for the background processor, so a panic during that wait fails shutdown: the panic guard is already cancelled, and the earlier snapshot is taken before the shutdown signal. The CI check now treats literal cargo b and cargo rustc mobile builds like cargo build.
Validation: python3 scripts/check_panic_unwind.py at this revision exited 0 and reported panic = unwind for the Android and Swift release-smaller builds. Matcher checks covered cargo b, cargo rustc, a toolchain prefix, and cargo ndk ... b, and rejected cargo bench and cargo install. panic_test.rs was not executed here; it needs bitcoind.
Earlier findings reconciled at this revision: 2 verified fixed.
Reviewer model: grok-4.7
Reasoning effort: xhigh
|
Merged: approved by @piotr-iohk, checks green, review threads answered. |
|
Released in v0.7.0-rc.84. |
Refs:
Description
release-smallerfrompanic = 'abort'topanic = 'unwind', so a Rust panic comes back as an error from the UniFFI call instead of aborting the app with SIGABRT, asbitkit-corealready does.releaseanddevkeepabort; no mobile build uses them.is_runningwith nothing processing or persisting. A panic hook records the panic, then each node built before it:ChannelManagerpersistPersistenceFailedfromstartuntil a newNodeis builtclose_channel,force_close_channel,splice_in,splice_out,update_channel_config,event_handled,claim_for_hashandfail_for_hashwithPersistenceFailedonce a panic occurred, so a stopped node cannot write channel statePersistenceFailedfromstopwhen a panic arrives while it waits for the background processor, because the final persist was skippedRisk of continuing after a panic. LDK aborts on purpose when persistence fails unrecoverably. Here the node writes nothing more from the processor, so disk holds what an abort would have left, apart from the moment before the guard runs, and the next
Nodetakes LDK's normal restart-after-crash path. LDK also poisons its monitors lock in that case, so later calls error.Residual risk. Other threads run briefly between the panic and the guard. The hook is process-wide, so a panic in a leftover task of a released node also stops a newer node.
What the apps do when a node stops itself today
ServiceQueueturns the panicking call intoAppError; direct getters (status,nodeId,channels,peers, balances) are outside it and can throwInternalException.Runningand calls fail withNotRunningorPersistenceFaileduntil the app stops and starts the node, which builds a newNode.ldk-nodecalls still crash throughtry!, as today.Cost on
arm64-v8a: the stripped library grows from 14.1 MB to 16.9 MB (+20%).Out of Scope
try!on non-throwing calls0.7.0-rc.84) and the twin app bumps that ship this; no binding API changesQA Notes
Manual Tests
Automated Checks
panic_test.rs, covering the refused calls and a panic duringstop, and a unit test inpanic.rscheck_panic_unwind.pyand thepanic-unwind.ymlworkflowpanic_test.rslocallyrelease-smallerfor Androidarm64-v8aandaarch64-apple-ios:panic_abortis linked only in the abort buildmain, with a trimmed copy ofrust.ymlbecausemainstops at its format and warning checks. The checks added after 04873ce act only after a panic and are covered bypanic_test.rs, run locally:reorg_testfailsderived_accounts::test_electrum_derived_account_incremental_sync_rolls_lookaheadstill running; that test passed in an earlier run of this branch and onmain.cpfp::test_cpfp_rejects_unknown_transactionfailed in the first attempt and passed in the secondmain:reorg_testfails the same assertion, andlsps2_client_service_integrationand onemulti_address_types_tests.rstest also failModels used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)