Microsoft.Data.SqlClient.ConnectionPool.ChannelDbConnectionPool
A connection pool implementation based on the channel data structure.
Provides methods to manage the pool of connections, including acquiring and releasing connections.
This implementation uses Channel<T> for managing idle connections,
which offers several advantages over the traditional WaitHandleDbConnectionPool:
Better async performance: Channels provide native async/await support without blocking
threads, unlike wait handles which can block managed threads and potentially cause thread pool starvation.
FIFO fairness: Channels guarantee first-come, first-served ordering for connection requests,
ensuring fair access to connections under high contention scenarios.
Reduced lock contention: The channel-based approach minimizes lock usage compared to
traditional synchronization primitives, improving scalability under concurrent load.
Simplified state management: Eliminates complex wait handle coordination and reduces
the potential for race conditions in connection lifecycle management.
The trade-off is slightly higher memory overhead per pool instance due to the channel infrastructure,
but this is generally offset by the performance benefits in async-heavy workloads.
public ConcurrentDictionary<DbConnectionPoolAuthenticationContextKey, DbConnectionPoolAuthenticationContext> AuthenticationContexts { get; }
Disposes the pool by calling Shutdown. Does not throw.
public DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionInternal oldConnection, TimeoutTimer timeout)
public bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> taskCompletionSource, TimeoutTimer timeout, out DbConnectionInternal connection)