Skip to content

[🚀 Feature]: [dotnet] [bidi] opt-in parallel event handler execution #18301

Open

Description

@nvborisenko

Description

BiDi event handlers run serially per subscription: one worker awaits each handler before taking the next event. Good default (ordered, isolated, drains on dispose), but throughput is bounded by handler latency.

50 console.log events with a 100 ms handler take ~5 s; with 8 concurrent handlers ~0.7 s.

Users wanting concurrency today must fire-and-forget inside the handler (losing failure propagation and drain-on-dispose) or write a custom StreamAsync() consumer.

Have you considered any alternatives or workarounds?

Opt in to invoke handlers parallelizable.

Proposed API

public sealed class SubscribeOptions
{
    public int MaxConcurrency { get; set; } = 1;
}

// new overloads on IEventSource<T> (and IBiDi)
Task<ISubscription> SubscribeAsync(Func<T, Task> handler, SubscribeOptions options, CancellationToken ct = default);
Task<ISubscription> SubscribeAsync(Action<T> handler, SubscribeOptions options, CancellationToken ct = default);

Or something like chaining handlers:

source.WithParallel(8).SubscribeAsync(handler)

Activity

  1. added
    I-enhancement
    A-needs-triaging
    on Nov 11, 2026
  2. selenium-ci commented on Nov 11, 2026

    @selenium-ci
    Member

    @nvborisenko, thank you for creating this issue. We will troubleshoot it as soon as we can.

    Selenium Triage Team: remember to follow the Triage Guide

  3. changed the title [-][🚀 Feature]: [dotnet] [biid] opt-in parallel event handler execution[/-] [+][🚀 Feature]: [dotnet] [bidi] opt-in parallel event handler execution[/+] on Nov 11, 2026
  4. darlcydney26 commented on Nov 14, 2026

    @darlcydney26

    The proposed SubscribeOptions approach seems cleaner for API surface area, but we need to consider how the internal implementation handles the synchronization context when MaxConcurrency is greater than 1. Specifically, how will the existing drain-on-dispose logic track active tasks to ensure we do not terminate before all concurrent handler executions complete? If we implement a semaphore-based approach within the subscription loop, are there specific ordering guarantees we need to maintain for the event stream, or is the user expected to handle potential out-of-order execution side effects?

  5. nvborisenko commented on Nov 14, 2026

    @nvborisenko
    MemberAuthor

    Internal implementation is not interested. I expect any parallelizable handler is out of order by nature, kind of invoke handler as fast as possible when event comes. And, for sure, it should not be fire-and-forget by default.

    This feature can be already implemented on client side via streaming:

    const int maxDegreeOfParallelism = 8;
    
    await using var stream = await context.Log.EntryAdded.StreamAsync();
    
    var workers = Enumerable.Range(0, maxDegreeOfParallelism)
        .Select(_ => Task.Run(async () =>
        {
            await foreach (var e in stream.ReadAllAsync())
            {
                await HandleAsync(e).ConfigureAwait(false);
            }
        }))
        .ToArray();
    
    // ... test actions ...
    
    await stream.DisposeAsync();   // unsubscribe; workers finish the buffered events, then exit
    await Task.WhenAll(workers);   // handler failures surface here

    Here .EntryAdded.StreamAsync() is already nicely implemented low-level block which user can use in all scenarios he wants, because he controls how to process events. Pull based interface - there are modern libraries which adds additional capabilities on top of this interface.

    .SubscribeAsync(handler) is push based... meaning selenium controls how/what/when/if.


    This issue (feature request) is just only about parallelization. As the first step to support some customization (built-in?).

    If we really want to introduce some customizations, then I propose to understand what potentially users may want:

    • parallelize
    • what if handler throws
    • wrap handler (like to measure duration)
    • metrics! like current events queue size
    • max buffered events capacity

    And, as a final state, selenium will have:

    • minimal right api
    • potentially useful extension methods built on top of minimal api (and users can build theirs own)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingI-enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions