fix: Arc::relocated() storage corruption when source == destination#310
fix: Arc::relocated() storage corruption when source == destination#310Darksecond merged 3 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #310 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 152 152
Lines 9335 9337 +2
=======================================
+ Hits 9335 9337 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…dd debug_assert for inconsistent source affinities Co-authored-by: Darksecond <291582+Darksecond@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a storage corruption bug in thread_aware::Arc::relocated() that occurs when the relocation source and destination refer to the same pinned slot, and adds a regression test to prevent recurrence.
Changes:
- Prevent overwriting the destination slot with the stale pre-relocation value when
source == destination. - Add a
debug_assert!intended to catch inconsistent source-affinity usage for closure factories. - Add a regression test covering the
source == destinationcorruption scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/thread_aware/src/cell/mod.rs | Avoids restoring the source slot when it aliases the destination; adds a debug assertion around closure-factory relocation source consistency. |
| crates/thread_aware/src/cell/tests.rs | Adds a regression test ensuring repeated relocation with source == destination does not corrupt storage / fast-path results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Please remove the debug_assert! @copilot |
Co-authored-by: Darksecond <291582+Darksecond@users.noreply.github.com>
Arc::relocated()corrupts shared storage whensource == destination: it stores the factory-created value at the destination slot, then unconditionally overwrites that same slot with the stale pre-relocation value. Any subsequentrelocated()call hits theget_clonefast-path and silently returns the wrong data.Changes
if source != destination— skips the overwrite when both affinities refer to the same slot.test_relocated_source_equals_destination_does_not_corrupt_storage— advances a counter to 42, relocates withsource == destination(factory resets to 0), then performs a second relocation; without the fix the second call would return 42 via the corrupted fast-path.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.