Skip to content

Fix COM connection-point cookie lifetime ownership - #135651

Draft
AaronRobinsonMSFT with Copilot wants to merge 3 commits into
mainfrom
copilot/remove-dangling-cookies
Draft

AaronRobinsonMSFT with Copilot wants to merge 3 commits into
mainfrom
copilot/remove-dangling-cookies

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Unadvise could delete a still-linked cookie when managed removal threw, or create multiple deleting owners during concurrent or reentrant removal. Publication and enumeration also exposed cookie pointers beyond their protected lifetime.

  • Ownership: Transfer constructing ownership to the list under CrstInterop; release remaining cookies at teardown.
  • Removal: Claim exclusively before managed callbacks. Restore retryability on failure; detach before deletion on success. Accessor side effects cannot be rolled back.
  • Enumeration: Replace retained pointers with a locked, live ID cursor. GC-root each subscriber under the lock, then perform COM conversion outside it; preserve position when cloning.
  • Regression coverage: Add throw-once retry, gated concurrent and reentrant removal, and enumeration mutation/reset/clone/ID-reuse cases.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copilot AI changed the title [WIP] Fix COM connection-point removal to handle cookies correctly Fix COM connection-point cookie lifetime ownership Oct 12, 2026
Comment thread src/coreclr/vm/comconnectionpoints.cpp Resolved
Comment thread src/coreclr/vm/comconnectionpoints.cpp Outdated
Comment on lines +1162 to +1163
while (pCookie != nullptr && pCookie->m_id < m_NextCookieId)
pCookie = CONNECTIONCOOKIELIST::GetNext(pCookie);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot This is a linear lookup. Is this introducing a performance issue that could create a performance cliff?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Rescanning from the head per item made a full traversal O(n²), including bulk Next and Skip. Fixed in 84c89c7 with a version-validated next-node cache: unchanged traversal is O(n) overall. Insert/unlink invalidates the cache under the lock before it can be dereferenced; recovery rescans by ID in O(n). Repeated mutations between items can still incur repeated scans.

Added coverage for bulk/single Next, multi-item Skip, and cloning valid/invalidated cursors. Linux builds passed, but this runner cannot compile/run Windows COM tests or measure their timings; the complexity improvement is source-derived, not benchmarked.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status
Status: No status

Development

Successfully merging this pull request may close these issues.

COM connection-point removal can leave dangling or multiply owned cookies

2 participants