Skip to content

Conversation

@andresilva
Copy link
Collaborator

@andresilva andresilva commented Aug 4, 2025

Use reference counting to track the lifecycle of Signal instances and coordinate proper shutdown. Each Signal contains an Arc<SignalGuard> that notifies a completion channel when dropped, allowing the runtime to know when all signal references have been released. The Spawner::stop() method is now async and waits on this completion channel, ensuring that all tasks holding Signal references have completed their cleanup work before shutdown finishes.

Shutdown Semantics

  • First stop() call: Initiates shutdown with provided exit value
  • Subsequent stop() calls: All wait on the same original completion, but the provided exit value is ignored
  • After shutdown is complete: stop() returns immediately without waiting
  • stopped() call: Returns a Signal that resolves to the original exit value. After the first stop() call this Signal always resolves immediately.

Fixes #1104.

@andresilva andresilva force-pushed the andre/signal-stop-wait branch from e798611 to baacd49 Compare August 4, 2025 21:02
Copy link
Contributor

@patrick-ogrady patrick-ogrady left a comment

Choose a reason for hiding this comment

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

This is VERY close to what I had in mind.

Nice work!

@andresilva
Copy link
Collaborator Author

andresilva commented Aug 6, 2025

I think I addressed all review comments now. I updated the PR description to describe the API behavior.

@patrick-ogrady
Copy link
Contributor

This is VERY close. Do you mind if I take it over to address a few small style things before merging (don't want to annoy you)?

@andresilva
Copy link
Collaborator Author

Sure no worries.

@patrick-ogrady patrick-ogrady merged commit 76def6c into commonwarexyz:main Aug 6, 2025
32 checks passed
@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 99.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.26%. Comparing base (65ee8a7) to head (4f9528c).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
runtime/src/lib.rs 99.09% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1357      +/-   ##
==========================================
+ Coverage   91.24%   91.26%   +0.01%     
==========================================
  Files         262      263       +1     
  Lines       65280    65476     +196     
==========================================
+ Hits        59565    59755     +190     
- Misses       5715     5721       +6     
Files with missing lines Coverage Δ
runtime/src/deterministic.rs 96.89% <100.00%> (+0.03%) ⬆️
runtime/src/tokio/runtime.rs 82.72% <100.00%> (+0.53%) ⬆️
runtime/src/utils/mod.rs 86.36% <ø> (-1.27%) ⬇️
runtime/src/utils/signal.rs 100.00% <100.00%> (ø)
runtime/src/lib.rs 96.72% <99.09%> (+0.28%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65ee8a7...4f9528c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[runtime] Improve Shutdown Tracking

2 participants