Repository navigation
Description
Summary
The engine's documented "safety-hang" mechanism — never auto-restart on a corrupted WAL, because an unsafe restart risks double-signing — is silently defeated by crates/test/app's own run() wiring, and the official tutorial (docs/tutorials/channels.md) teaches the exact same broken pattern verbatim. The process exits with status 0 instead of hanging, which is the one thing this mechanism exists to prevent.
Related to #1434 (WAL replay corruption tolerance), but distinct: that issue is about whether detection/replay correctly tolerates tail corruption from an interrupted append. This issue is about what happens after detection correctly triggers the safety-hang path — the engine does the right thing, but the application layer that wraps it doesn't keep the process alive.
Background
crates/engine/src/util/failure.rs's hang_on_safety_failure is correct and unit-tested in isolation: on a safety-critical failure (e.g. WAL CRC mismatch), it casts NodeMsg::SafetyFailure and then pending::<()>().awaits forever — that future provably never resolves. crates/engine/src/node.rs's Node actor is designed to stay alive during this state (stop children, keep running) specifically so an external process supervisor sees a stuck, not-exited process and doesn't restart it.
Root cause
crates/test/app/src/node.rs (and identically, docs/tutorials/channels.md):
let app_handle = tokio::spawn(
async move {
if let Err(e) = crate::app::run(&mut state, &mut channels).await {
tracing::error!(%e, "Application error");
}
}
.instrument(span),
);async fn run(self) -> eyre::Result<()> {
let handles = self.start().await?;
handles.app.await.map_err(Into::into)
}Two independent defects:
- The app task's
Erris only logged, never propagated — the spawned task'sJoinHandle<()>always completesOk(()). run()only awaitshandles.app—handles.engine.handle(the realNodeactor's handle, which is the one designed to never resolve during safety-hang) is never consulted in the exit path at all; it's only ever.abort()-ed on explicit shutdown.
Steps to reproduce
cd code
cargo build -p arc-malachitebft-test-app
BIN=target/debug/malachitebft-test-app
$BIN testnet --home /tmp/malachite-repro --nodes 1
$BIN start --home /tmp/malachite-repro/0 --validator &
PID=$!
# let it write a few WAL entries, then crash it
sleep 1 && kill -9 $PID
# corrupt one byte inside a WAL entry (not the header)
python3 -c "
with open('/tmp/malachite-repro/0/wal/consensus.wal', 'r+b') as f:
f.seek(300); b = f.read(1); f.seek(300); f.write(bytes([b[0]^0xFF]))
"
$BIN start --home /tmp/malachite-repro/0 --validator
echo "exit code: $?"ERROR ...: Safety-critical failure; hanging to prevent unsafe auto-restart reason=Corrupted WAL entry encountered: CRC mismatch
ERROR ...: Entering safety-hang state: stopping all children, Node remains alive — operator intervention required before restart
...
exit code: 0
The process exits within milliseconds despite the log claiming it "remains alive."
Impact
Under any supervisor configured to always restart a validator (systemd Restart=always, Docker restart: unless-stopped, Kubernetes restartPolicy: Always — all common for "keep my validator online"), this is exactly the unsafe auto-restart the mechanism exists to prevent. Under a supervisor that only restarts on failure, exit code 0 looks like an intentional, successful stop — no alert at all.
This isn't just a test-harness bug: docs/tutorials/channels.md teaches this exact code, including the comment "The run method... lets the node run until it is stopped (ideally never)" — directly contradicted by the measured behavior. Anyone following the tutorial for the channel-based integration inherits the identical gap.
Suggested fix
let app_handle = tokio::spawn(
async move { crate::app::run(&mut state, &mut channels).await }.instrument(span),
);(requires widening Handle.app from JoinHandle<()> to JoinHandle<eyre::Result<()>>)
async fn run(self) -> eyre::Result<()> {
let mut handles = self.start().await?;
tokio::select! {
result = &mut handles.engine.handle => {
// Node supervisor itself terminated — clean shutdown, or a
// liveness failure the engine judged safe to restart from.
result.map_err(|e| eyre::eyre!("Node actor task panicked: {e}"))
}
result = &mut handles.app => {
// App loop ended on its own — may be mid safety-hang. Don't
// exit on this alone; log, then defer to the handle that only
// resolves on a genuine shutdown.
match result {
Ok(Ok(())) => {}
Ok(Err(e)) => tracing::error!(%e, "Application error"),
Err(e) => tracing::error!(%e, "Application task panicked"),
}
(&mut handles.engine.handle).await
.map_err(|e| eyre::eyre!("Node actor task panicked: {e}"))
}
}
}Verified: with the patch applied, the identical repro leaves the process alive (confirmed via kill -0 8s later, no exit) instead of exiting. A normal testnet run with --validator is unaffected.
This should land in both crates/test/app/src/node.rs and docs/tutorials/channels.md. Happy to open a PR for both if useful.
Activity
romac commentedon Nov 3, 2026
Thanks for the report, this issue is already known internally and will be fixed in the next release.