[dotnet] Safe modifications of internal log handlers#17334
[dotnet] Safe modifications of internal log handlers#17334nvborisenko merged 3 commits intoSeleniumHQ:trunkfrom
Conversation
Review Summary by QodoRefactor LogHandlerList with copy-on-write for thread safety
WalkthroughsDescription• Refactored LogHandlerList to use copy-on-write pattern for thread safety • Removed inheritance from List<ILogHandler> for safer handler modifications • Implemented explicit IEnumerable<ILogHandler> to support safe iteration • Added blank line in LogContext.cs for improved readability File Changes1. dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs
|
Code Review by Qodo
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the .NET internal logging handler collection to avoid InvalidOperationException-style issues when handlers are modified during enumeration (copy-on-write snapshotting), and includes a minor formatting tweak.
Changes:
- Refactor
LogHandlerListto stop inheriting fromList<ILogHandler>and use an internal handler array with custom add/remove/clear + enumeration. - Update enumeration to iterate over a stable snapshot of handlers.
- Minor whitespace-only change in
LogContext.cs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
dotnet/src/webdriver/Internal/Logging/LogHandlerList.cs |
Replaces List<T> inheritance with snapshot-array storage and custom mutation/enumeration methods. |
dotnet/src/webdriver/Internal/Logging/LogContext.cs |
Adds a blank line in the constructor for readability (but currently includes trailing whitespace). |
Make is safe to modify log handlers while iterating.
💥 What does this PR do?
This pull request refactors the
LogHandlerListclass to improve its internal implementation and thread safety. The class no longer inherits fromList<ILogHandler>, and now manages its own internal array of handlers. This change also updates how handlers are added, removed, and enumerated, ensuring a more robust and maintainable design.LogHandlerList refactoring and improvements:
LogHandlerListto no longer inherit fromList<ILogHandler>, instead implementing its own internal storage with a volatile array for thread safety.Add,Remove, andClearmethods to operate on the internal_handlersarray, removing use of base class methods and ensuring modifications are thread-safe.IEnumerable<ILogHandler>explicitly to allow enumeration over the internal array of handlers.using System.Collections;to support the new enumeration implementation.Minor code style improvement:
LogContext.csfor improved readability.🔧 Implementation Notes
Copy-on-write approach to achieve immutability internally.
🔄 Types of changes