有一个带有自托管SignalR应用程序的Windows服务 .

服务:

using (var webApp = WebApp.Start(url))
{
    _logger.Info($"SignalR running on: {url}");

    while (!token.IsCancellationRequested)
    {
        await Task.Delay(100);
    }
}

启动:

CookieAuthenticationOptions cookieOptions = new CookieAuthenticationOptions()
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    CookieName = ConfigurationManager.AppSettings["CookieName"],
    CookieDomain = cookieDomain,
    AuthenticationMode = AuthenticationMode.Active,
    Provider = new AuctionCookieAuthenticationProvider()
};

app.UseCookieAuthentication(cookieOptions);
app.MapSignalR(new HubConfiguration() { EnableDetailedErrors = true, });
GlobalHost.HubPipeline.RequireAuthentication();
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new SignalRUserIdProvider());

当客户端连接集线器时一切顺利,但当活动连接数达到100-150时,我收到以下错误:

请求处理期间的异常 . System.Data.Entity.Core.EntityException:基础提供程序在Open上失败 . System.Data.SqlClient.SqlException:连接超时已过期 . 尝试使用登录前握手确认时超时时间已过 . 这可能是因为登录前握手失败或服务器无法及时响应 . 尝试连接到此服务器所花费的时间是 - [Pre-Login] initialization = 5;握手= 14986; System.ComponentModel.Win32Exception:等待操作超时---内部异常堆栈跟踪的末尾在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection owningObject,UInt32的waitForMultipleObjectsTimeout,布尔allowCreate,布尔onlyOneCheckConnection,DbConnectionOptions USEROPTIONS,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection owningObject,TaskCompletionSource1重试,DbConnectionOptions USEROPTIONS,在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection DbConnectionInternal&连接)(的DbConnection owningConnection,TaskCompletionSource1重试,DbConnectionOptions USEROPTIONS,DbConnectionInternal oldConnection,DbConnectionInternal&连接)System.Data.ProviderB上的System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry,DbConnectionOptions userOptions) System.Data的System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)上的System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)中的ase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry,DbConnectionOptions userOptions) .SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken)---从抛出异常的先前位置开始的堆栈跟踪---在System.Runtime.CompilerServices.TaskAwaiter的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处 . HandleNonSuccessAndDebuggerNotification在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy(任务的任务) . <> c__DisplayClass4 . <b__3> d__6.MoveNext()---从先前的位置,其中引发异常---在System.Runtime堆栈跟踪结束 . System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNoti上的CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.d__91.MoveNext()中的fication(任务任务)---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)在System.Data.Entity.Core.EntityClient.EntityConnection . <OpenAsync> d__8.MoveNext()---内部异常堆栈跟踪的末尾在System.Data.Entity.Core.EntityClient.EntityConnection . <OpenAsync> d__8.MoveNext()---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) )在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)在System.Data.Entity.Core.Objects.ObjectContext . <EnsureConnectionAsync> d__9.MoveNext()---从先前位置栈跟踪的结尾,其中引发异常---在System.Runtime.Compi堆的lerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)在System.Data.Entity.Core.Objects.ObjectContext . <ExecuteInTransactionAsync> d__3d1.MoveNext()---完从先前的位置在那里引发异常---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(工作任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(工作任务)在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy追查 . d__91.MoveNext()---从抛出异常的前一个位置开始的堆栈跟踪结束--- atSystem.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(工作任务)在System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult在System.Data.Entity的(工作任务)() . Core.Objects.ObjectQuery1 . <GetResultsAsync> d__e.MoveNext()---在抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) . 堆的CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification在System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult()在System.Data.Entity.Internal.LazyAsyncEnumerator1(任务的任务) . <FirstMoveNextAsync> d__0.MoveNext()---完来自抛出异常的先前位置的跟踪---在Sy的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处stem.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions . <FirstOrDefaultAsync> d__251.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)at Microsoft.AspNet.Identity.TaskExtensions.CultureAwaiter1.GetResult()中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务),位于Microsoft.AspNet.Identity.Owin.SecurityStampValidator . <> c__DisplayClass23 . <b__1> d__4.MoveNext() ---在抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处 . Microsoft.Owin.Security.Cookies.CookieAuthenticationHandler.d__2.MoveNext()中的CompilerServices.TaskAwaiter.ValidateEnd(任务任务)---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.d__0.MoveNext()---堆的结束从先前的位置在那里引发异常---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(工作任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(工作任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware1追查 . <Invoke> d__0.MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处( Microsoft.Owin.Cors.CorsMiddleware上的任务任务 . <Invoke> d__0.MoveNext()---从抛出异常的上一个位置开始的堆栈跟踪结束---在系统中.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)在Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware2.d__0.MoveNext()---堆栈跟踪结束从以前的位置在那里引发异常---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(工作任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(工作任务)在Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2 . d__0.MoveNext()---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)中在Microsoft.Owin.Host.HttpListener.OwinHttpListener.d__5.MoveNext()

Windows防火墙已关闭 . 当我按照那里的指示:

我发现了这个问题:SQL Server Pre-Login Handshake,但我不明白我应该在EF中调用 SqlConnection.ClearPool(connection); .

连接字符串:

Data Source=DTLN-AUC-SQL.dtln-cislink.lan;Initial Catalog=Auction2013;Integrated Security=True;MultipleActiveResultSets=True;Max Pool Size=20000