使用NServicebus的Windows服务SqlTransport和Persistence会引发超时异常

时间:2016-09-08 07:57:44

标签: .net sql-server windows-services timeout nservicebus

我们在Windows服务中使用NServiceBus和SqlServerTransport以及NHibernatePersistence(使用TopShelf和Autofac作为IOC)。

这一切都运行了几个小时,但一段时间后服务开始抛出SQL Timeout异常。 连接到同一数据库的其他应用程序没有其他问题,NServicebus升级到最新版本(5.2.15)。

我想到的第一件事是已达到Max SQL服务器连接池(默认为100),但我不确定。

NServicebus配置如下:

var _busConfiguration = new BusConfiguration();

_busConfiguration.EnableInstallers();
_busConfiguration.UseSerialization<JsonSerializer>();
_busConfiguration.UsePersistence<NHibernatePersistence>()
                 .ConnectionString(_Connectionstring)
                 .DisableSchemaUpdate();

_busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(scope));

_busConfiguration.Transactions()
                 .Enable()
                 .DisableDistributedTransactions();

_busConfiguration.UseTransport<SqlServerTransport>()
                 .DefaultSchema("dbo")
                 .ConnectionString(_Connectionstring);

这是堆栈跟踪

WARN  2016-09-07 19:07:55,528 16868322ms SqlServerPollingDequeueStrategy          Warn               - An exception occurred when connecting to the configured SQLServer instance 
System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName, Boolean shouldReconnect)
   at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName)
   at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso)
   at NServiceBus.Transports.SQLServer.NativeTransactionReceiveStrategy.TryReceiveFrom(TableBasedQueue queue)
   at NServiceBus.Transports.SQLServer.AdaptivePollingReceiver.Try(Boolean& success)
   at NServiceBus.Transports.SQLServer.AdaptiveExecutor`1.ReceiveLoop(Object obj)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
ClientConnectionId:513b75a0-db8a-43ef-9964-acac90933f58
Error Number:-2,State:0,Class:11

INFO  2016-09-07 19:07:55,528 16868322ms RepeatedFailuresOverTimeCircuitBreaker   InfoFormat         - The circuit breaker for SqlTransportConnectivity is now in the armed state 
WARN  2016-09-07 19:07:55,793 16868587ms SqlServerPollingDequeueStrategy          Warn               - An exception occurred when connecting to the configured SQLServer instance 
System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

任何人都知道我可以尝试什么?

0 个答案:

没有答案