Skip to content

cuprated: Add graceful shutdown, pt2: service error propagation#586

Open
redsh4de wants to merge 26 commits intoCuprate:mainfrom
redsh4de:feat/graceful-shutdown-pt2
Open

cuprated: Add graceful shutdown, pt2: service error propagation#586
redsh4de wants to merge 26 commits intoCuprate:mainfrom
redsh4de:feat/graceful-shutdown-pt2

Conversation

@redsh4de
Copy link
Copy Markdown
Contributor

@redsh4de redsh4de commented Feb 20, 2026

What

Depends on pt1, PR #585

Building on part 1, this replaces the panic-on-error patterns in cuprated's services with error propagation that makes use of the graceful shutdown mechanism

Why

So we dont panic and insta-crash upon a error, shutdown should be graceful. Internal errors still caused panics before this via PANIC_CRITICAL_SERVICE_ERROR

Where

  • cuprated
    • Base
      • monitor.rs - added spawn_critical to TaskExecutor, which logs errors and triggers shutdown on task end
      • constants.rs - removed PANIC_CRITICAL_SERVICE_ERROR
    • Blockchain
      • manager.rs - use spawn_critical for syncer and manager tasks
      • handler.rs - replace all .expect(PANIC_CRITICAL_SERVICE_ERROR) with ?/.map_err(), add HandleBlockError enum to distinguish validation errors from service errors, functions return anyhow::Result
      • interface.rs - add IncomingBlockError::Service variant, replace .expect() with .map_err()
      • syncer.rs - suppress IncomingBlockChannelClosed error if shutting down
      • blockchain.rs - check_add_genesis returns anyhow::Result
    • Txpool
      • manager.rs - same expect to ? pattern, spawn_critical, functions return anyhow::Result
      • incoming_tx.rs - add IncomingTxError::Service variant, error handling for incoming tx path
    • P2P
      • request_handler.rs - add HandlerError enum (Peer vs Service), replace expect with typed error propagation, log service errors
    • RPC
      • server.rs - spawn to spawn_critical with ? propagation
      • json_rpc.rs - handle IncomingBlockError::Service in submit_block, trigger shutdown
      • other_json.rs - pass shutdown token to tx handler
      • tx_handler.rs - handle IncomingTxError::Service, trigger shutdown

How

spawn_critical wraps each subsystem's future: if it returns an error it is logged and the shutdown token is hit, triggering the same graceful shutdown path as OS signals.

Critical tasks returning Ok(()) also trigger shutdown.

Validation errors (invalid blocks/transactions from peers) are distinguished from service errors (database/internal failures) using simple enums (HandleBlockError, HandlerError). Only service errors propagate to shutdown - validation errors are handled gracefully (ban peer, cancel downloader, etc.)

@github-actions github-actions bot added the A-binaries Area: Related to binaries. label Feb 20, 2026
@redsh4de redsh4de marked this pull request as draft February 28, 2026 14:35
@github-actions github-actions bot added the A-p2p Area: Related to P2P. label Feb 28, 2026
@redsh4de redsh4de marked this pull request as ready for review March 1, 2026 14:41
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from aac614a to 1a41630 Compare March 15, 2026 22:15
@redsh4de redsh4de marked this pull request as draft March 17, 2026 18:13
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 91f6723 to e3d9960 Compare March 18, 2026 02:13
@github-actions github-actions bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. and removed A-p2p Area: Related to P2P. labels Mar 18, 2026
@redsh4de redsh4de marked this pull request as ready for review March 18, 2026 02:25
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from e3d9960 to 0cf53be Compare March 18, 2026 03:38
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 0cf53be to 15bc617 Compare March 19, 2026 00:42
@github-actions github-actions bot added the A-consensus Area: Related to consensus. label Mar 19, 2026
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 15bc617 to b5cfe8a Compare March 19, 2026 07:35
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from b5cfe8a to 157451c Compare March 20, 2026 09:14
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 157451c to 8adc7f1 Compare March 21, 2026 10:16
@redsh4de redsh4de force-pushed the feat/graceful-shutdown-pt2 branch from 8adc7f1 to 79e3e61 Compare March 24, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-binaries Area: Related to binaries. A-consensus Area: Related to consensus. A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant