Repository navigation
fix(orchestrator): wait for processes to properly exit when restarting - #11744
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Process shutdown can report success while subprocesses in the managed process group remain alive.
Review effort: Balanced
Findings: 1
What changed in this PR
Refactors orchestrator process management to support reliable stop-and-restart behavior.
Changes:
- Waits for termination, escalating from
SIGTERMtoSIGKILL. - Restarts processes when relevant runtime arguments change.
- Exposes lock-independent process observers to the dashboard.
| File | Description |
|---|---|
rs/orchestrator/src/upgrade.rs |
Delegates restart decisions to process managers. |
rs/orchestrator/src/processes.rs |
Adds restart policies and process observers. |
rs/orchestrator/src/process_manager.rs |
Implements blocking process termination and escalation. |
rs/orchestrator/src/orchestrator.rs |
Wires managers and observers independently. |
rs/orchestrator/src/dashboard.rs |
Generalizes process PID reporting. |
rs/orchestrator/src/boundary_node.rs |
Migrates boundary-node lifecycle management. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Will wait for #11349 before merging to patch its |
|
@pierugo-dfinity I noticed the test
|
| attempt (variant, commit) | early node → laggard | early stop → start | broadcast | laggard INVALID | laggard is_halted |
check | laggard restart |
|---|---|---|---|---|---|---|---|
_local 10-15 a1 (1ca9400), H+1000=1150 |
ahvf4 → mcvwc | 13:20:17.678 → .698 | 20.509 | 20.514 | 22.774 | 22.397 (s6l7u fails first) | after log end (~27.7) |
| 56mic → s6l7u | 18.173 → .193 | 20.952 | 20.968 | 22.584 | after log end | ||
_local 10-14 a1 (79cb31a), 1165 |
nb4mb → 6ft42 | 14:57:51.338 → .448 | 53.520 | 53.546 | 55.571 | 57.103 | 58:01.876 |
_local 10-14 a2 (79cb31a), 1135 |
hrv6f → tnxux | 15:07:57.331 → .411 | 59.633 | 59.647 | 08:01.466 | 08:02.956 | 08:06.549 |
_local 10-02 a1 (b03af7c), 1195 |
wcfxc → ygtsh | 14:15:~47.0 (driver) | 49.529 (driver) | 49.548 (driver) | – | 55.133 | ~57.05 (driver) |
_farm 10-06 a1 (3f6d405), 1180 |
4ejqw → qlstf | 09:13:50.308 → .332 | 54.654 | 54.669 | not before log end | 58.146 | ~59.4 (extrapolated) |
_head_nns_farm 10-14 a1 (79cb31a), 1165 |
niv4o → i3gwu | 15:00:14.500 → .524 | 16.801 | 16.808 | 18.942 | 20.450 | ~24.0 (extrapolated) |
_farm 10-02 a1 (b03af7c) |
6nik3 → cwzx4 | 14:12:53.297 → .323 | 55.616 | 55.626 | 58.452 | 58.961 | 13:04.249 |
- In every failure, the node that exceeded the limit was still running its boot-time replica at check time. No restarted replica ever logged an INVALID.
- The receiver de-duplicates by CUP id, so the counter is exactly 1 even when several early nodes send the CUP.
- The check panics at the first node that exceeds the limit. In 10-15 it stopped at s6l7u, so mcvwc's INVALID was never reported.
The two gates explain the laggards that did not invalidate:
- Not connected. In
_local10-14 a1, dximx and 4buzm had lower NodeIds than nb4mb, so they had to re-dial nb4mb's new process themselves. They halted at 55.51–55.52 and re-dialed only at 57.14. Result: no INVALID. - Already halted. In
_farm10-06 a1, z7avg and 3g7dt were connected to 4ejqw's new process from 50.71, but had loadedis_haltedat 53.38, before its broadcast at 54.65. Result: no INVALID. qlstf stored the recovery version only at 54.650, so it was still validating and invalidated the CUP at 54.669. - Passing attempts. 5 of the 12 PR attempts with a straddle passed, because one of the gates closed in time. The margins were sometimes 43–159 ms. With both gates included, the model classifies all 7 failed and all 27 checkable passed PR attempts correctly.
Master counterfactual
- Straddles do happen on master. In 16 of the 109 Oct 9–15 runs, laggards picked up the recovery a tick late (7 runs) or not before the log ended (9 runs). Under the PR's same-tick restart, 44 of 222 master runs (19.8%) would have had a laggard's old replica still alive after an early node's new replica could have come up.
- Master never starts the new replica in the stop tick. Stop → new start was 10.009–11.279 s (median 10.043 s, n=59). Example from
rca_master_local2026-10-14T16:10:22:- h2hwr stopped at 16:15:47.702 and started again at 57.762, with its stack up at 16:16:00.443.
- Its 3 laggards had loaded
is_haltedat 51.69 and stopped at 57.89–58.04. - No INVALID was logged.
- Master's passing check is weak evidence on its own. 63% of app-replica metric reads on master failed with ECONNREFUSED and were silently skipped; in 53 of 109 runs no app replica was read at all. With 0 INVALID lines in the logs, nothing was hidden, though.
Mechanism in code
Line references are at 7546892bae unless marked with the PR commit 1ca94005d4.
Orchestrator on master (rs/orchestrator/src/):
upgrade.rs:408-416:stop_replica_if_recovery_cup_or_subnet_changed, thenensure_children_are_running. There is no await between them.upgrade.rs:640-680: "Found higher unsigned CUP" leads tostop_replica.process_manager.rs:124-143,213-219:stopiskill, which sends SIGTERM to the process group and returns.process_manager.rs:221-241:is_runningispid_cell.is_some(). Only thewait_on_exitthread clears the PID, after the child has been reaped.processes.rs:267-270:ensure_runningreturns early whileis_running(). The next tick then starts the replica.- No other master path starts the replica sooner. The only exceptions are the NNS-failover re-exec, which needs
registry_store_uri(Nonein this test), and the re-exec after a failed stop (never hit).
Orchestrator on the PR:
processes.rs:75-105(1ca94005d4):ReplicaProcess::restart_decisionreturns Restart when the CUP is unsigned andheight > cup_height. The boot replica hascup_height0, hence the logged "(height 1150 > 0)".processes.rs:361-386(1ca94005d4):ensure_runningcallsstop()?and then falls through to build and start the new process.process_manager.rs:283-318(1ca94005d4):stopsends SIGTERM, waits up to 30 s, then sends SIGKILL and waits up to 10 s. In practice the replica aborts (wait status 6) 13–110 ms after SIGTERM.
Tick cadence:
orchestrator.rs:50,533-536:CHECK_INTERVAL_SECS= 10 s, slept after each check. The measured period is 10.02–10.15 s.- The registry replicator polls every 5 s (
rs/config/src/nns_registry_replicator.rs:20).check()reads the latest registry version once, at its start (upgrade.rs:178). - The VMs boot together, so the app nodes' ticks are roughly in phase. Each node's 5 s replicator and 10 s loop are phase-correlated, so whether the store lands just before or just after a node's own tick is often close to a coin flip.
- Tick start times are not logged; they are inferred from the "Persisting CUP" cadence (±0.3 s).
Sending the unsigned CUP:
rs/artifact_pool/src/consensus_pool.rs:464-483:init_genesisputs the startup CUP into the validated pool.consensus_pool.rs:956-963:get_all_for_initial_broadcastalways includes the highest validated CUP.rs/replica/setup_ic_network/src/lib.rs:557-599:create_artifact_handlerruns right afterDkgKeyManager::new, which logs "Finished waiting on 2 transcripts".rs/p2p/artifact_manager/src/lib.rs:146-152,256-280: the initial artifacts are sent asDeliver.rs/p2p/consensus_manager/src/sender.rs:253-300: the sender re-checks the peer set every 5 s.rs/p2p/quic_transport/src/connection_manager.rs:273-292: only the lower NodeId dials.- The CUP cannot reach the old replica any other way. The replica reads its CUP file only at startup, and
/_/catch_up_packageis read-only.
Invalidating it on the old replica:
rs/consensus/src/consensus/priority.rs:111: a CUP is alwaysWants.rs/consensus/src/consensus/validator.rs:1716-1757: H+1000 is within the validation range.rs/consensus/cup_utils/src/lib.rs:150-185: the signer check passes.rs/crypto/src/sign/threshold_sig.rs:407:CspSignature::try_fromfails before the registry lookup at:409. The error is reproducible, so it becomesInvalidArtifact.consensus_pool.rs:498-499,771-780:HandleInvalidincrementsinvalidated_artifactsand logs the WARN.
Halting:
halt_at_cup_heightonly blocks block making and batch delivery. The old replicas keep logging "Batch of height H+1 is not delivered because replica is halted", which showson_state_changeand the validator keep running.rs/registry/canister/src/mutations/do_recover_subnet.rs:71-80: the recovery turnshalt_at_cup_heightintois_halted=true.rs/consensus/src/consensus.rs:406-414: withis_halted, consensus returns before any subcomponent, including the validator.- The replica's registry client polls the local store every 5 s (
rs/interfaces/registry/src/lib.rs:13). From local store to "consensus is halted by instructions" took 0.17–4.85 s.
Metric check:
rs/tests/driver/src/driver/group.rs:469-480: the default replica metrics includeconsensus_invalidated_artifactswith a maximum of 0.rs/tests/driver/src/driver/test_env_api.rs:1128-1182: one read per node per endpoint. An unreachable node is skipped with an INFO line, and the first node over its limit panics.group.rs:650-671:update_orchestrator_metrics_to_check, which the panic message suggests, only edits the orchestrator map, so it cannot relax this replica metric. Onlyremove_metrics_to_checkcan.
Scope
Why only cup_explorer_test. It is the only system test that both halts with halt_at_cup_height alone and recovers via RecoverSubnet with an unchanged replica version, and it ends about 8 s after the proposal. The sr_* tests are not affected:
- Some take the subnet offline first (
is_halted), so the old replicas stop validating. - Others change the replica version, which gives
ReplicaVersionMismatch→RemoveFromUnvalidated, with no metric. - All of them wait for finalization above 1000 on every app node before the check, so the laggards have restarted with fresh counters.
On the PR branch, 264 of 266 recovery-test runs passed, and the 2 flakes have unrelated signatures. The nested nr_* NNS recovery tests never ran on this PR.
Production (unverified). ic-recovery's Halt step takes the subnet offline before any recovery CUP exists, so old replicas never validate it, on master or on the PR. The chain:
rs/recovery/src/app_subnet_recovery.rs:439-452lib.rs:274-290admin_helper.rs:84-119rs/registry/admin/bin/main.rs:935-958(DOWN_FOR_REPAIRS)do_set_subnet_operational_level.rs:226-232(is_halted=true)
Only flows that rely on halt_at_cup_height alone, or recover an un-halted subnet, are exposed. Nobody checked whether alerts use this metric or the WARN.
Flake rate
- Once a straddle happens, NodeId order and the 5 s registry-poll phase decide pass or fail, sometimes by tens of ms. The outcome is effectively random, so a timing tweak will not make the test reliable.
- A replay of master's timings with the PR's same-tick restart and both gates predicts about 9–14% failed attempts, depending on the baseline week. Observed: 20% (7/35). That is roughly consistent at these sample sizes.
- The PR does not change tick or replicator timing.
CHECK_INTERVAL_SECSand the replicator are untouched, and the tick-phase distributions match master.
Fix directions (untested, ranked)
- Consensus: don't send unsigned CUPs. In
get_all_for_initial_broadcast,.filter(|cup| cup.is_signed())atconsensus_pool.rs:956-963.- It removes the cause: no peer can ever validate another node's unsigned CUP, and every orchestrator builds the registry CUP itself.
- Unsigned CUPs sent by malicious peers still count as invalid.
/_/catch_up_packageand the CUP explorer are unaffected.- Only
test_get_all_validatedneeds adjusting, because fake CUPs are unsigned. - This belongs to the consensus team and would be a separate PR. Edge case, not verified: the unsigned random beacon at the recovery height can be invalidated only if the recovery height equals the old replica's beacon tip + 1.
- Test: wait for all app nodes to restart. In
cup_explorer_test, after recovery, wait until every app node's orchestrator has restarted the replica, i.e.orchestrator_processes_start_attempts_total{process_name="replica"} >= 2on :9091. Then the check reads the new replicas.- This makes the test deterministic and fits in fix(orchestrator): wait for processes to properly exit when restarting #11744. It costs at most about 15 s.
- It hides the old replica's count by resetting it rather than removing the cause, which goes against the intent of test: expand
assert_no_critical_errorsto also allow checking other metrics + add a default check in system tests that no consensus artifacts were invalidated #8815.
- Receiver side:
RemoveFromUnvalidatedinstead ofHandleInvalidwhen an unsigned CUP fails crypto.- This loses the signal for misbehaving peers.
- It only helps once the pre-recovery replica version contains it.
- An up-front
is_signed()check would break validator unit tests that use unsigned fake CUPs.
remove_metrics_to_check("consensus_invalidated_artifacts"). This is too blunt: it disables the check for all nodes and both sub-tests. Acceptable only as a commented stopgap pointing at option 1.- Orchestrator: defer the start to the next tick. This is a timing hack. It brings back about 10 s of downtime and breaks two of the PR's new unit tests (
processes.rs:612,upgrade.rs:3631-3691).
Not evaluated: have the test set is_halted before RecoverSubnet, as ic-recovery does. That would change what the test covers.
Caveats
- Not reproduced on demand. The evidence is log forensics over 7 failed attempts, 27 checkable passed PR attempts and 222 master runs, plus code reading at both revisions.
- Timestamps. Cross-node orderings at the millisecond level are within clock uncertainty: ≤ about 65 ms for
_localon 10-14/15 and about 50 ms on farm. The 10-02_localnode clocks were corrected by 0.6–1.55 s. Causality rests on the code path plus consistent co-occurrence, not on strict timestamp order. - Test version. 6 of the 7 tested PR commits ran the test from before feat(cup_explorer): extract the threshold master public keys of a CUP #11786/fix: deflake //rs/tests/consensus:cup_explorer_test #11841: no
test_extract_master_public_keys, and a different system-subnet DKG interval. The app-subnet mechanism is unaffected. - Not checkable. The
_farm2026-10-15 attempt cannot be classified, because its ES logs end before the recovery. Master_farmruns have no node logs.
Other flakes on the PR branch this month (unrelated signatures)
sr_app_same_nodes_with_chain_keys_test_head_nns_local: setup SSH health timeout.sr_app_no_upgrade_enable_chain_keys_test_farm_colocate:ValidateReplayOutput, the known ic-replay race.standard_engine_replica_version_test_local: "never came back online", also FLAKY 4 times on master.ipv4_integration_test_head_nns_localandquery_stats_above_threshold_local: different errors, not investigated.
Files
- Logs. PR
_local:2026-10-16T07:24:57/, and2026-10-16T07:25:50/2026-10-02T14:16:01_*. PR farm with ES IC logs:../rca_pr_farm/. Master_localpasses:../rca_master_local/. rca/scripts/:jr.py: journald JSON extractor (jr.py LOG [regex] [--node P] [--crate R]).recovery_timeline.py: per-node recovery timeline.scan_runs.py: one line per attempt.
rca/agent_reports/: verdicts of the verification workflow. 5 investigations (orchestrator timing, replica gossip and validation, farm ES logs, metric check, fix directions), 3 skeptics (none refuted the claim, all with high confidence) and a completeness critic.rca/agent_work/: their scripts and outputs. Notable:skeptic_mech/halt_margin*: master's structural margin.skeptic_mech/gated_cf*: the gated rate model.replica_lens/bin/gates.py: the connection and halted gates.metric_lens/master_straddle_partial.txt: the master straddle and partial runs.
|
Thank you Bas this is very helpful! |
|
Summarized the issue and suggested fix number 1 in #11873 |
…nable_chain_keys_test_farm_colocate (dfinity#11818) ## Problem `//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate` flaked once in the week up to 2026-10-11 ([2026-10-05 16:19 UTC](https://dash.dm1-idx1.dfinity.network/invocation/b6dca5c2-ade4-4df4-94c4-d5d47bda5ff1?target=//rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate), on PR dfinity#11744's branch). The recovery tool failed in `ValidateReplayOutput`: ``` Execution of step ValidateReplayOutput failed: Output error: Invalid output: Replay height smaller than certification height. ``` `ic-replay` had replayed 45 batches up to height 245 (the certification height), delivered the extra checkpointing batch 246 and logged `Created unverified checkpoint @246`, `Computed root hash ... of state @246` and `Validated checkpoint @246`. Yet its `ReplayOutput` reported the latest CUP's state, `StateParams { height: 200, hash: f3f4ff1b... }`, so the validation compared 200 - 1 against 245. In the passing attempts `Height after replay` is the certification height + 1, as intended since dfinity#11203. ## Root cause `Player::get_latest_state_params` read the hash of the latest state once and treated *any* `Err` from `get_state_hash_at` as "the latest state exists in memory only", falling back to the latest CUP. That read can fail transiently for a checkpoint that already exists on disk: - For a checkpoint round, `commit_and_certify` enqueues `ComputeManifest` and `ValidateReplicatedStateAndFinalize` on the tip channel, then has the hash thread insert `states_metadata[height]` (without a manifest yet) and publish the new `latest_state_height`, waits for it, and only then enqueues the follow-up `WaitForManifest` request that publishes the manifest (and `ResetTipAndMerge`). - `ic-replay`'s `wait_for_state` polls `latest_state_height` every 500 ms and then calls `flush_tip_channel`. If it observes the new height before `WaitForManifest` is enqueued, its `Wait` request lands between `ValidateReplicatedStateAndFinalize` and `WaitForManifest`: the flush returns as soon as the checkpoint is validated, while the root hash is still unpublished, and `get_state_hash_at` returns `Transient(HashNotComputedYet)`. The failing log shows this interleaving. Checkpoint 246 was created and its certification hash computed at 16:19:36.635; `ic-replay` saw height 246 at .664 (one poll later) and its flush returned at .797, right after `Validated checkpoint @246`; two further `wait_for_state` calls at .797 and .798 returned immediately, so `WaitForManifest` was still not enqueued; `ReplayOutput { height: 200 }` was printed at .975, and `ResetTipAndMerge` (enqueued together with `WaitForManifest`) ran at .969, during the state manager's drop. Why `commit_and_certify` needed more than 160 ms between publishing the height and enqueueing the follow-ups is inferred, not shown: the hash thread persists the states metadata with an fsync before it answers, and this run's checkpoint creation took 470 ms against 10 ms in the passing attempt. The window exists since async hashing moved the height publication onto the hash thread (dfinity#8464, reverted in dfinity#10001, re-landed as dfinity#10071 on 2026-05-08); the single read in `ic-replay` dates from 2022. This is not only a flake: the recovery tool went on to delete every checkpoint but the highest (246) while the state params it would put into the recovery CUP were those of height 200. `ValidateReplayOutput` caught it here, but the corrupted-CUP recoveries skip that step. ## Fix Read the hash with the existing `get_state_hash` helper, which retries transient errors every second and returns `None` only for `StateNotFullyCertified`, i.e. a state that really exists in memory only; the fallback to the CUP (or, without a consensus pool, to the highest checkpoint, now read the same way) is unchanged for that case. The helper answers height 0, which is never a checkpoint, with `None` without polling (an empty state directory would otherwise make the state manager report it as not committed yet forever), so `update-registry-local-store` on an empty state fails as before instead of waiting. Unit tests pin both `None` cases down. Behaviour changes to be aware of: a `StateRemoved` error for the latest state, which cannot happen, now panics instead of silently reporting the CUP; and like `verify_latest_cup`, which already used the helper, the poll is unbounded, so a manifest that is never published would make `ic-replay` log "Waiting for state hash" every second rather than report a wrong height. Follow-up for the state manager (not in this PR): `flush_tip_channel` is documented to finish "all asynchronous checkpointing operations, including ... manifest computation", but a caller on another thread can flush before `commit_and_certify` has enqueued `WaitForManifest`. `ic-replay` was the only such caller; the other callers flush from the committing thread. Not related to dfinity#11795: that change only touches the Local backend's bridge, and this run was colocated on Farm. ## Testing - `cargo check --all-targets --all-features -p ic-replay`, `cargo fmt`, `./ci/scripts/rust-lint.sh`. - `bazel build //rs/replay:replay`; `bazel test //rs/recovery:recovery_test //rs/replay:player_integration_tests //rs/replay:replay_doc_test //rs/replay:replay_test` (rerun after each review follow-up). - `bazel test --runs_per_test=3 --jobs=3 //rs/tests/consensus/subnet_recovery:sr_app_no_upgrade_enable_chain_keys_test_farm_colocate`: 3/3 passed on Farm (372 s, 390 s, 380 s), each with `Height after replay` = certification height + 1. Passing runs cannot exercise the window, which needs the checkpoint's I/O to be slow; the evidence for the fix is the log analysis above and the unit tests. This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
…lica before the crypto vault (dfinity#11874) `ipv4_integration_test_head_nns_local` flaked on dfinity#11744 after removing its unassigned node and letting it register itself again: the registry stayed at version 3 until the 180 s timeout. The cause is a race in the test's re-registration script that already exists on master: 1. The script stopped `ic-crypto-csp` (the crypto vault) before `ic-replica` (the orchestrator). The vault is socket-activated, and the orchestrator's vault client reconnects about 100 ms after losing its connection. If the orchestrator is still alive at that point, the reconnect starts a new vault, which can read the old `public_keys.pb` and `sks_data.pb` before the script deletes them. 2. The node then comes back with its old keys and node ID. The orchestrator checks its registration only once at startup, against a local registry copy that predates the removal. The check passes silently, so the node never registers again. On master the vault was started again this way in 4 of 223 `_local` attempts (2026-10-02..16). A failure also needs the new vault to read the key files before the `rm`. The same timeout failed 4 Farm runs in Jan–Mar 2026. The fix changes both scripts that use this pattern: `ipv4_integration_test` and `node_registration_test_common`, which the two node registration tests share. - Stop `ic-replica` first, then `ic-crypto-csp.socket` together with `ic-crypto-csp.service`. No vault client is left to reconnect, and the closed socket cannot start the vault before the keys are deleted. Start the socket and the service again afterwards. - Assert that the node registered with a new node ID. This catches a node re-registering under its old ID, where the test would otherwise pass. That happened once on master in `node_registration_with_node_allowance_test_local`. Verification, with local `_local` runs: - Master's script with `sleep 0.3` between the two stops, which forces the reconnect, failed 2 of 2 runs with the flake's signature: the old node ID and a timeout at registry version 3. - With this change, `ipv4_integration_test_local`, `ipv4_integration_test_head_nns_local`, `node_registration_with_node_allowance_test_local` and `node_registration_with_max_rewardable_nodes_test_local` passed, and each node registered with a new ID. Labelled `CI_ALL_BAZEL_TARGETS` so that CI runs these system tests: `ipv4_integration_test` is a `long_test`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
CUPs taken from the registry, like genesis or recovery CUPs, are unsigned but totally legitimate and end up in the replica's validated pool on [replica startup](https://sourcegraph.com/r/github.com/dfinity/ic@a5a6d8d45414a0303af808c8ef38eb428e5b89ea/-/blob/rs/artifact_pool/src/consensus_pool.rs?L481), without checking their signatures (which would fail because empty). P2P then replicates this artifact to the other peers' unvalidated pools, which cannot validate it since the signature is missing and this could raise an alert for suspicion of malicious behaviour. Luckily, this rarely happens in production because: - On genesis, the other peers will not pull this artifact because they already have it in their own pools (passed by their own orchestrator). - On recoveries, the same reasoning applies though there is still a window where replica A has restarted with the new unsigned CUP, that replica B pulls while still running the old replica. In practice though, the subnet is normally [halted](https://sourcegraph.com/r/github.com/dfinity/ic@a5a6d8d45414a0303af808c8ef38eb428e5b89ea/-/blob/rs/recovery/src/app_subnet_recovery.rs?L35-40) and thus [does not validate any artifact](https://sourcegraph.com/r/github.com/dfinity/ic@a5a6d8d45414a0303af808c8ef38eb428e5b89ea/-/blob/rs/consensus/src/consensus.rs?L407-415). - On recoveries where the subnet is not `is_halted` but is `halt_at_cup_height` (like in verifiable recoveries for resharing chain-keys), there the validator still runs. For now, the alert never triggered probably because the orchestrator stops the replica and restarts it only at the next iteration of the upgrade loop 10 seconds later, which considerably reduces the timing window. With dfinity#11744 though, the replica will be restarted right away, and we might observe this alert. For good practice, do not make replicas broadcast unsigned CUPs during pool initialization since other replicas would not be able to validate it anyways. Kudos to @basvandijk for detecting the flakiness on the aforementioned PR and suggesting a fix! --------- Co-authored-by: Leo Eichhorn <[email protected]>


There is quite a lot going on in this PR. It is more of a
refactorof the orchestrator's process manager but it still introduces the following functional changes (motivated by existing issues, thusfix):Today, when
stopping a process, we just send aSIGTERMand instantly return. There's no guarantee that the process actually terminated, just that "it probably will in the future". This is great for not blocking the thread, but it is in contradiction withic-boundarywhen the domain name changes,ic-gatewaywhen its config changes.This PR thus modifies
stopto block until the process actually terminated: ifstopreturnedOk(()), the process is guaranteed to have terminated, which fixes the cases above.Moreover,
stopdoes so by waiting up to 30 seconds, then tries again withSIGKILLfor up to 10 seconds. This is in concordance with how systemd does it and allows force-killing a stuck process. This also means that this function could take up to 40 seconds to return, and blocks a tokio worker thread doing so (though I think that's acceptable since it should be very rare and the runtime has many threads).The previous point means that the upgrade loop could hold a write-lock on
MultipleProcessesManagerfor up to 40 seconds, preventing the dashboard from serving the processes' PIDs (that need a read-lock to that manager). Provide the dashboard with only a view of the processes' PIDs, not needing a lock on the entire manager. Also generalize over any number of processes with a type-erasedtrait ProcessObserver.ic-boundary's PID on the dashboard.Today, the
stop_replica_if_recovery_cup_or_subnet_changedfunction in the upgrade loop is fragile because it assumes we will always reach it on the iteration where we observe the recovery CUP or subnet-split. Though, if there was an error between the observation and that call, then the next iteration would not re-observe it and the replica would not be restarted (this was already mentioned here).Process. This allows to simplify the upgrade loop and to remove theIcBoundaryManager's custom restart logic by including it directly intoProcessManager<P>for anyP: Process.