Skip to content

Conversation

jkoritzinsky
Copy link
Member

Instead of writing to _cache while under a reader lock, delay the cleanup until we can acquire a writer lock.

We do this instead of doing an upgradeable lock as ReaderWriterLockSlim only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.

This matches the logic in the .NET 9 CoreCLR implementation of ComWrappers.

Reverts #120370
Fixes #120470

Instead of writing to `_cache` while under a reader lock, delay the cleanup until we can acquire a writer lock.

We do this instead of doing an upgradeable lock as `ReaderWriterLockSlim` only supports one upgradeable reader thread at a time, removing the benefit of having an rwlock in the first place.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reverts a previous change that replaced a ReaderWriterLockSlim with a simple Lock in the RcwCache class, restoring the reader-writer lock mechanism for better concurrency. The change improves the cache's ability to handle concurrent read operations while ensuring thread-safe cleanup of dead entries.

Key changes:

  • Replaces the simple Lock with ReaderWriterLockSlim for the RcwCache
  • Implements a two-phase locking strategy in FindProxyForComInstance to avoid upgradeable locks
  • Updates all cache operations to use appropriate read/write locks with proper try-finally blocks

Copy link
Contributor

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

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) October 13, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Linux/x64: 2 Regressions on 10/3/2025 9:18:21 PM +00:00

2 participants