Repository navigation
Harden windows-future result and handler ownership - #5480
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The unsafe Send/Sync and COM lifetime changes require Windows runtime validation of apartment dispatch, teardown, and reentrant release that was unavailable in this review environment.
No open issues 🎉
What changed in this PR
Strengthens result and completion-handler ownership in windows-future, addressing part of #5469's thread-safety concerns. COM initialization remains the application's responsibility.
Changes:
- Require
Send + Syncfor ready results andSendfor spawned results. - Share agile delegate storage with
Eventto marshal retained non-agile completion handlers. - Add compile-fail, apartment-lifetime, and C++ interoperability coverage, plus COM usage guidance.
| File | Description |
|---|---|
crates/tests/libs/future/tests/completed_started.rs |
Adds apartment, marshaling, and COM initialization tests. |
crates/tests/libs/future/tests/agile.rs |
Checks result bounds and preserves consumer/progress flexibility. |
crates/tests/libs/future/src/lib.rs |
Adds compile-fail checks for unsupported result types. |
crates/tests/libs/future/Cargo.toml |
Enables doctests and required Windows test APIs. |
crates/tests/interop/fixtures/async_methods/handlers.h |
Tests native handler ownership, registration races, and apartment shutdown. |
crates/tests/interop/fixtures/async_methods/client.cpp |
Runs the new native handler tests. |
crates/libs/future/src/future.rs |
Conditions future thread-safety traits on the underlying async type. |
crates/libs/future/src/async_spawn.rs |
Requires transferable results and marshals retained completion handlers. |
crates/libs/future/src/async_ready.rs |
Requires thread-safe stored results. |
crates/libs/future/readme.md |
Documents application-owned COM initialization and callback requirements. |
crates/libs/core/src/imp/mod.rs |
Exposes the shared agile delegate helper. |
crates/libs/core/src/imp/agile_delegate.rs |
Adds reusable direct-or-marshaled delegate storage. |
crates/libs/core/src/event.rs |
Reuses the shared helper for event delegates. |
Review effort: Balanced
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Require
Send + Syncfor ready results andSendfor spawned results, and marshal retained non-agile completion handlers using storage shared withEvent. COM initialization stays with the application.Part of #5469.