-
Notifications
You must be signed in to change notification settings - Fork 55
feat(platform-wallet)!: shared ThreadRegistry for coordinator lifecycle + shutdown UAF/data-loss fixes #3954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Claudius-Maginificent
wants to merge
30
commits into
v3.1-dev
Choose a base branch
from
feat/platform-wallet-shutdown-join
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
f3354f6
feat(platform-wallet)!: shutdown() joins coordinator threads and retu…
lklimek 261178e
fix(platform-wallet): RAII-guard is_syncing so a coordinator panic ca…
lklimek 42d734d
refactor(rs-dash-async): add AtomicFlagGuard RAII helper
lklimek 6e78b77
fix(platform-wallet): refine CoordinatorThreadStatus variants + tight…
lklimek 5f80450
test(rs-dash-async): assert AtomicFlagGuard contract + add #[must_use]
lklimek 6b2cd39
fix(platform-wallet): make coordinator passes cancellable + converge …
lklimek 13a22dd
fix(platform-wallet): bound clear_shielded + tidy shutdown docs/logging
lklimek 93b8954
fix(platform-wallet-ffi): timeout-bound the shielded sync stop bridge
lklimek 747f5f0
Merge branch 'v3.1-dev' into feat/platform-wallet-shutdown-join
lklimek 2bd9501
fix(platform-wallet)!: close residual coordinator-thread UAF on shutdown
lklimek 7c975ed
fix(platform-wallet)!: surface non-clean shielded drain on clear/stop
lklimek 5f63c95
fix(platform-wallet): reap prior coordinator thread outside backgroun…
lklimek 2b068ba
fix(platform-wallet): close shielded epilogue TOCTOU + pin restart reap
lklimek 5017ba1
fix(swift-sdk): retain wallet callback context on incomplete shutdown
lklimek b491773
test(platform-wallet): bound cleanup quiesce in restart-reap regressi…
lklimek 76c8bee
fix(platform-wallet): track detached coordinator threads so shutdown(…
lklimek 3cca1cf
perf(platform-wallet): drain coordinators concurrently in shutdown() …
lklimek 8c52811
feat(dash-async): add shared ThreadRegistry worker-lifecycle engine
lklimek ac9a51a
feat(dash-async): key-scope parked orphans for any_alive_for()
lklimek d20aed0
refactor(platform-wallet): migrate sync coordinators onto shared Thre…
lklimek d190f29
test(dash-async): anchor DrainHook compile_fail doctest to E0277 + no…
lklimek 3e81fc1
fix(dash-async,platform-wallet): harden ThreadRegistry lifecycle + do…
lklimek 911f99f
refactor(platform-wallet): extract CoordinatorLifecycle to dedup the …
lklimek 22647a7
fix(platform-wallet): raise quiescing gate in CoordinatorLifecycle::q…
lklimek 7f3aeb5
fix(dash-async): park a restarted worker's prior under the slot lock …
lklimek 41791c0
fix(platform-wallet-ffi): gate shielded_sync_stop success on orphan l…
lklimek 4b099a9
fix(platform-wallet): bound clear_shielded's drain and hold its quies…
lklimek 7be68c5
refactor(dash-async): full spawn-failure rollback + drop stale doc hi…
lklimek 3821389
docs(swift-sdk): broaden deinit comment for shielded_sync_stop's orph…
lklimek 748c4f8
fix(platform-wallet): make the quiescing<->is_syncing handshake self-…
lklimek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
|
||
| /// RAII guard that clears an [`AtomicBool`] flag to `false` on drop. | ||
| /// | ||
| /// Callers set the flag to `true` before constructing the guard (typically | ||
| /// via a `compare_exchange`); the guard resets it on every exit path, | ||
| /// including panics, so a panicked holder can never leave the flag wedged. | ||
| /// | ||
| /// **Panic-strategy caveat:** the clear-on-panic guarantee relies on | ||
| /// destructors running while the stack unwinds, so it holds under | ||
| /// `panic = "unwind"` (the default). Under `panic = "abort"` — e.g. the | ||
| /// iOS release profiles — a panic aborts the process immediately and no | ||
| /// `Drop` runs; there is simply no "after" left for the flag to gate. | ||
| #[must_use = "AtomicFlagGuard clears the flag on drop; binding to `_` or using as a statement drops it immediately"] | ||
| pub struct AtomicFlagGuard<'a>(&'a AtomicBool); | ||
|
|
||
| impl<'a> AtomicFlagGuard<'a> { | ||
| /// Wrap `flag`. Does **not** set it to `true` — the caller is | ||
| /// responsible for doing that before constructing the guard. | ||
| pub fn new(flag: &'a AtomicBool) -> Self { | ||
|
Claudius-Maginificent marked this conversation as resolved.
|
||
| Self(flag) | ||
| } | ||
| } | ||
|
|
||
| impl Drop for AtomicFlagGuard<'_> { | ||
| fn drop(&mut self) { | ||
| self.0.store(false, Ordering::Release); | ||
|
Claudius-Maginificent marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::panic::{catch_unwind, AssertUnwindSafe}; | ||
|
|
||
| /// A guard constructed over a `true` flag holds it while in scope and | ||
| /// clears it to `false` on a normal scope exit. | ||
| #[test] | ||
| fn clears_flag_on_normal_drop() { | ||
| let flag = AtomicBool::new(true); | ||
| { | ||
| let _guard = AtomicFlagGuard::new(&flag); | ||
| assert!(flag.load(Ordering::Acquire), "flag stays set while held"); | ||
| } | ||
| assert!(!flag.load(Ordering::Acquire), "flag cleared on drop"); | ||
| } | ||
|
|
||
| /// The clear also runs while unwinding a panic — the load-bearing | ||
| /// property the sync coordinators lean on so a panicked pass can't | ||
| /// leave `is_syncing` latched and wedge `quiesce()`'s drain. | ||
| #[test] | ||
| fn clears_flag_while_unwinding_panic() { | ||
| let flag = AtomicBool::new(true); | ||
| let result = catch_unwind(AssertUnwindSafe(|| { | ||
| let _guard = AtomicFlagGuard::new(&flag); | ||
| panic!("boom while holding the guard"); | ||
| })); | ||
| assert!(result.is_err(), "the panic propagated out of catch_unwind"); | ||
| assert!( | ||
| !flag.load(Ordering::Acquire), | ||
| "Drop ran during unwinding and cleared the flag" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.