[dotnet] [bidi] Thread safe events registration#17210
[dotnet] [bidi] Thread safe events registration#17210nvborisenko merged 3 commits intoSeleniumHQ:trunkfrom
Conversation
Review Summary by QodoImplement thread-safe event handler management with copy-on-write array
WalkthroughsDescription• Replace List<EventHandler> with thread-safe copy-on-write array • Add locking mechanism for handler modifications in EventRegistration • Encapsulate handler access through AddHandler, RemoveHandler, GetHandlers methods • Improve thread safety during concurrent event subscription and processing File Changes1. dotnet/src/webdriver/BiDi/EventDispatcher.cs
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Pull request overview
Refactors .NET BiDi EventDispatcher handler storage to reduce per-event allocations and improve thread safety during event dispatch by switching from a mutable List<EventHandler> to a copy-on-write array with locked updates.
Changes:
- Replace
EventRegistration.Handlers(List<EventHandler>) with a copy-on-writeEventHandler[]. - Add
AddHandler/RemoveHandlerAPIs guarded by a private lock. - Iterate event handlers via
GetHandlers()without allocating a per-dispatch snapshot.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
dotnet/test/common/BiDi/Session/SessionTests.cs:54
- Same issue here: the lambda returns a
Taskand is not awaited, soThrows.InstanceOf<TaskCanceledException>()won’t reliably observe the cancellation. Prefer an async delegate (async () => await bidi.StatusAsync(...)) orAssert.ThrowsAsyncwhen asserting exceptions from async APIs.
public void ShouldRespectCancellationToken()
{
using var cts = new CancellationTokenSource(TimeSpan.FromMicroseconds(1));
Assert.That(
() => bidi.StatusAsync(cancellationToken: cts.Token),
Throws.InstanceOf<TaskCanceledException>());
}
This pull request refactors the event handler management in the
EventDispatcherclass to improve thread safety and performance. The main change is replacing the use of aList<EventHandler>with a copy-on-write array and introducing locking for handler modifications.🔄 Types of changes