Repository navigation
Prevent clipboard hangs during concurrent data-store access - #15319
Conversation
Co-authored-by: Copilot <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15319 +/- ##
===================================================
+ Coverage 37.84861% 39.30648% +1.45786%
===================================================
Files 246 246
Lines 9789 9805 +16
Branches 1031 1032 +1
===================================================
+ Hits 3705 3854 +149
+ Misses 5920 5775 -145
- Partials 164 176 +12
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the clipboard data-store synchronization change.
No open issues 🎉
What changed in this PR
This PR addresses a dictionary-corruption race in the clipboard data store shared by WinForms and WPF, which can cause concurrent clipboard operations to fail or hang.
Changes:
- Adds per-store synchronization for dictionary access and coherent entry snapshots, keeping validation, deserialization, and format mapping outside the lock.
- Adds regression tests for concurrent access, callback reentrancy, format compatibility, and native storage-medium ownership.
- Documents the synchronization boundary and unchanged payload-ownership rules.
| File | Description |
|---|---|
| src/System.Private.Windows.Core/tests/System.Private.Windows.Core.Tests/System/Private/Windows/Ole/DataStoreTests.cs | Adds concurrency, reentrancy, compatibility, and native ownership regression tests. |
| src/System.Private.Windows.Core/src/System/Private/Windows/Ole/DataStore.cs | Synchronizes dictionary operations and preserves first-entry insertion after validation. |
| docs/shared-wpf-infrastructure.md | Documents the store gate, callback restrictions, and payload-lifetime boundary. |
Review effort: Balanced
|
/backport to release/11.0 |
|
Started backporting to |
|
/backport to release/10.0 |
|
Started backporting to |
|
@Shyam-Gupta backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Prevent clipboard hangs during concurrent access
Using index info to reconstruct a base tree...
A docs/shared-wpf-infrastructure.md
M src/System.Private.Windows.Core/src/System/Private/Windows/Ole/DataStore.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): docs/shared-wpf-infrastructure.md deleted in HEAD and modified in Prevent clipboard hangs during concurrent access. Version Prevent clipboard hangs during concurrent access of docs/shared-wpf-infrastructure.md left in tree.
Auto-merging src/System.Private.Windows.Core/src/System/Private/Windows/Ole/DataStore.cs
CONFLICT (content): Merge conflict in src/System.Private.Windows.Core/src/System/Private/Windows/Ole/DataStore.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Prevent clipboard hangs during concurrent access
Error: The process '/usr/bin/git' failed with exit code 128 |
…ccess (#15334) Fixes [3084829](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3084829) Backport of #15319 to release/10.0 /cc @Shyam-Gupta @nareshjo ## Root Cause The clipboard data store reads, writes, and enumerates its format dictionary without synchronization. Concurrent mutation can corrupt dictionary state; on .NET Framework, a corrupted bucket chain can cause a later lookup to loop indefinitely. ## Proposed changes - Protect the clipboard data store's format dictionary against overlapping managed calls and COM callbacks. - Capture complete entries and coherent format snapshots while keeping validation, deserialization, and format mapping outside the per-store gate. - Cover concurrent insertion and overwrites, callback reentrancy, format compatibility, and native storage-medium ownership with regression tests. ## Customer Impact - The synchronization gap was identified while investigating customer-reported clipboard hangs. This change addresses a dictionary-corruption race that can cause clipboard operations to fail or hang. - Existing format mapping and native drag-and-drop ownership behavior are preserved; no public API changes. ## Regression? - Unconfirmed. The unsynchronized dictionary predates this change; an introducing release has not been established. ## Risk Low expected compatibility risk. The per-store gate protects dictionary access and snapshot creation; validation, deserialization, format mapping, and explicit COM calls stay outside locked sections. Payload ownership is unchanged. Lock contention and larger snapshots add potential performance costs. ## Test methodology - Exercise colliding concurrent insertions, concurrent reads and overwrites, complete data/flag publication, and coherent format enumeration. - Verify validation and deserialization callbacks can wait for another thread to access the store. Check format mapping/order, validation failures, serializable first-entry behavior, and native-medium ownership. - Rebuild the affected test project with the repository's Arcade workflow in Debug and Release. Run the final DataStore regression tests on both targets: 10 Framework cases and 11 modern .NET cases per configuration, totaling 42 passes with no failures or skips. - Exercise the exact timeout-cleanup block in an isolated Framework harness with completed, cancellable, and delayed workers. All three checks passed; this checks cleanup behavior, not product COM contention. - Basic copy/paste and undo smoke checks with a consumer using the same production fix completed without observed failures. The original intermittent hang has not been reproduced and verified fixed. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15334)
…ccess (#15329) Fixes [3084829](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/3084829) Backport of #15319 to release/11.0 /cc @Shyam-Gupta @nareshjo ## Root Cause The clipboard data store reads, writes, and enumerates its format dictionary without synchronization. Concurrent mutation can corrupt dictionary state; on .NET Framework, a corrupted bucket chain can cause a later lookup to loop indefinitely. ## Proposed changes - Protect the clipboard data store's format dictionary against overlapping managed calls and COM callbacks. - Capture complete entries and coherent format snapshots while keeping validation, deserialization, and format mapping outside the per-store gate. - Cover concurrent insertion and overwrites, callback reentrancy, format compatibility, and native storage-medium ownership with regression tests. ## Customer Impact - The synchronization gap was identified while investigating customer-reported clipboard hangs. This change addresses a dictionary-corruption race that can cause clipboard operations to fail or hang. - Existing format mapping and native drag-and-drop ownership behavior are preserved; no public API changes. ## Regression? - Unconfirmed. The unsynchronized dictionary predates this change; an introducing release has not been established. ## Risk Low expected compatibility risk. The per-store gate protects dictionary access and snapshot creation; validation, deserialization, format mapping, and explicit COM calls stay outside locked sections. Payload ownership is unchanged. Lock contention and larger snapshots add potential performance costs. ## Test methodology - Exercise colliding concurrent insertions, concurrent reads and overwrites, complete data/flag publication, and coherent format enumeration. - Verify validation and deserialization callbacks can wait for another thread to access the store. Check format mapping/order, validation failures, serializable first-entry behavior, and native-medium ownership. - Rebuild the affected test project with the repository's Arcade workflow in Debug and Release. Run the final DataStore regression tests on both targets: 10 Framework cases and 11 modern .NET cases per configuration, totaling 42 passes with no failures or skips. - Exercise the exact timeout-cleanup block in an isolated Framework harness with completed, cancellable, and delayed workers. All three checks passed; this checks cleanup behavior, not product COM contention. - Basic copy/paste and undo smoke checks with a consumer using the same production fix completed without observed failures. The original intermittent hang has not been reproduced and verified fixed. ## Test environment(s) - Windows x64, Debug and Release. - .NET Framework 4.8.1 target (`net481`). - Modern target: `net11.0-windows7.0`, executed using the repository-selected .NET runtime `12.0.0-alpha.1.26519.114`. - Repository-local .NET SDK: `12.0.100-alpha.1.26480.102`. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15329)
Related to #15319 and #15346. ## Proposed changes - Add real cross-process clipboard lock exhaustion and recovery tests, including the original failure HRESULT. - Exercise delayed Unicode rendering during replacement, checking clipboard ownership and preservation of posted messages. - Extend negative retry argument tests to both copy modes and `int.MinValue`. ## Customer Impact - Protects clipboard replacement and delayed reading from contention regressions. - Verifies expected exceptions, recovery, and queued-message preservation. ## Regression? - No; adds coverage for existing behavior. ## Risk - Low. Test-only changes using the existing sequential collection, STA attributes, and RemoteExecutor ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15384)
Fixes 3084829
Root Cause
The clipboard data store reads, writes, and enumerates its format dictionary without synchronization. Concurrent mutation can corrupt dictionary state; on .NET Framework, a corrupted bucket chain can cause a later lookup to loop indefinitely.
Proposed changes
Customer Impact
Regression?
Risk
Low expected compatibility risk. The per-store gate protects dictionary access and snapshot creation; validation, deserialization, format mapping, and explicit COM calls stay outside locked sections. Payload ownership is unchanged. Lock contention and larger snapshots add potential performance costs.
Test methodology
Test environment(s)
net481).net11.0-windows7.0, executed using the repository-selected .NET runtime12.0.0-alpha.1.26519.114.12.0.100-alpha.1.26480.102.Microsoft Reviewers: Open in CodeFlow