Skip to content

Harden windows-future result and handler ownership - #5480

Merged
Kenny Kerr (kennykerr) merged 1 commit into
masterfrom
future-result-ownership
Nov 24, 2026
Merged

Kenny Kerr (kennykerr) merged 1 commit into
masterfrom
future-result-ownership

Conversation

@kennykerr

Copy link
Copy Markdown
Collaborator

Require Send + Sync for ready results and Send for spawned results, and marshal retained non-agile completion handlers using storage shared with Event. COM initialization stays with the application.

Part of #5469.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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 + Sync for ready results and Send for spawned results.
  • Share agile delegate storage with Event to 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

@kennykerr
Kenny Kerr (kennykerr) merged commit b669da2 into master Nov 24, 2026
51 checks passed
@kennykerr
Kenny Kerr (kennykerr) deleted the future-result-ownership branch November 24, 2026 13:31
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.

2 participants