Skip to content

cuprated: Add graceful shutdown#585

Merged
Boog900 merged 2 commits into
Cuprate:mainfrom
redsh4de:feat/graceful-shutdown
May 19, 2026
Merged

cuprated: Add graceful shutdown#585
Boog900 merged 2 commits into
Cuprate:mainfrom
redsh4de:feat/graceful-shutdown

Conversation

@redsh4de
Copy link
Copy Markdown
Contributor

@redsh4de redsh4de commented Feb 18, 2026

What

Ports over the graceful shutdown logic from fjall-wip branch: https://github.com/Cuprate/cuprate/blob/fjall-wip/binaries/cuprated/src/monitor.rs

Depends on the embeddable version #592

Why

More idiomatic shutdown pattern, previously every exit was equivalent to a crash

Where

  • cuprated:
    • monitor.rs - TaskExecutor handle (cancellation token + task tracker)
    • config.rs - target_max_memory / fjall_cache_size / block_downloader_config return Result instead of panicking on unresolved memory
    • main.rs - wires up executor, OS signal handler, double-Ctrl+C force exit, shutdown wait loop
    • commands.rs - add Exit command
    • blockchain/manager.rs, syncer.rs - shutdown token in select loops, replace todo!() with break
    • txpool/manager.rs, incoming_tx.rs - shutdown token, change ordering by priority due to using biased
    • rpc/server.rs - with_graceful_shutdown on axum, tracked spawns, shutdown token plumbed through
    • rpc/handlers/other_json.rs - wiring for stop_daemon RPC
    • lib.rs - Node::launch returns Result, creates and distributes TaskExecutor, Drop impl
  • storage/blockchain:
    • database.rs - detach drop-log info! from caller span

How

monitor.rs introduces TaskExecutor, took nomenclature inspo from reth. Instead of how reth does it though with a static, its threaded into the functions to support running multiple Node instances in the same process

All tokio::spawn replaced with TaskExecutor::spawn. Task select loops now use biased ordering with the shutdown token as higher priority.

On shutdown signal, the token is cancelled -> tasks wind down one by one, and main() waits on task tracker to finish unwinding before dropping the runtime.

Node::launch now returns Result<Self, anyhow::Error> instead of panicking on database/service init failures.

Double Ctrl+C force exits.

@github-actions github-actions Bot added the A-binaries Area: Related to binaries. label Feb 18, 2026
@redsh4de redsh4de marked this pull request as draft February 18, 2026 21:43
@redsh4de redsh4de marked this pull request as draft February 18, 2026 21:43
@redsh4de redsh4de marked this pull request as ready for review February 19, 2026 15:58
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from 83cb650 to 3e39aa8 Compare March 15, 2026 19:58
@redsh4de
Copy link
Copy Markdown
Contributor Author

Reworking this to depend on #592, ignore for now

@redsh4de redsh4de marked this pull request as draft March 17, 2026 18:12
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from 90c91bf to 3fdda0f Compare March 17, 2026 23:16
@github-actions github-actions Bot added the A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. label Mar 17, 2026
@redsh4de
Copy link
Copy Markdown
Contributor Author

Depends on #592 now.

@redsh4de redsh4de marked this pull request as ready for review March 17, 2026 23:47
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch 2 times, most recently from 9e7a372 to 628803c 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 branch 3 times, most recently from 31b5645 to db027a4 Compare March 24, 2026 22:43
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch 6 times, most recently from b9fb288 to 96b81dd Compare April 26, 2026 19:53
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from 96b81dd to c854901 Compare May 5, 2026 12:06
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from c854901 to 8b853be Compare May 12, 2026 15:58
@github-actions github-actions Bot added the A-storage Area: Related to storage. label May 12, 2026
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch 2 times, most recently from 69ba849 to cc90a18 Compare May 14, 2026 00:10
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch 2 times, most recently from a2e0d9a to e0b279c Compare May 18, 2026 00:50
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from e0b279c to 85388a0 Compare May 18, 2026 19:52
@github-actions github-actions Bot removed A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-consensus Area: Related to consensus. labels May 18, 2026
Copy link
Copy Markdown
Member

@SyntheticBird45 SyntheticBird45 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let a few comment but overall lgtm

Comment thread binaries/cuprated/src/blockchain/syncer.rs
Comment thread binaries/cuprated/src/commands.rs
Comment thread binaries/cuprated/src/config.rs Outdated
Comment thread binaries/cuprated/src/lib.rs
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from 1fbee3c to f485cff Compare May 19, 2026 09:26
@redsh4de redsh4de force-pushed the feat/graceful-shutdown branch from f485cff to 00e6773 Compare May 19, 2026 09:37
@Boog900 Boog900 merged commit 467a168 into Cuprate:main May 19, 2026
13 of 19 checks passed
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-storage Area: Related to storage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants