简体   繁体   English

Azure SQL 单个数据库 DTU 超时过期错误

[英]Azure SQL Single Database DTU Timeout Expired Error

I am using Azure SQL Single database DTU purchase model.我用的是Azure SQL 单库DTU采购model。 The average load seems to be under 10%.平均负载似乎低于 10%。 From time to time I am receiving an error, now it's happening almost each day.有时我会收到一个错误,现在几乎每天都在发生。 I am using EF Core 3.1 for database access.我正在使用 EF Core 3.1 进行数据库访问。 The database is accessed from an API built with ASP.NET core 3.1 and deployed on a Linux Azure App service.该数据库是从使用 ASP.NET 内核 3.1 构建的 API 访问的,并部署在 Linux Z3A580F1402293867F AppF 服务上。
The error is:错误是:
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (258): Unknown error 258

Stack trace:堆栈跟踪:

An exception occurred in the database while saving changes for context type 'MTP.Api.Persistence.MTPDbContext'.
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
 ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
 ---> System.ComponentModel.Win32Exception (258): Unknown error 258
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
ClientConnectionId:16f899d4-cfc9-4401-b631-1b4d547c4c19
Error Number:-2,State:0,Class:11
ClientConnectionId before routing:02e37a1e-981c-4ff6-9437-cade8b401cc5
Routing Destination:c71faab34237.tr1.francecentral1-a.worker.database.windows.net,11018
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)

Any idea what could cause this?知道是什么原因造成的吗? Or how I can find what is causing the problem?或者我怎样才能找到导致问题的原因?

I updated the nuget package Microsoft.Data.SqlClient to version 2.0.我将 nuget package Microsoft.Data.SqlClient 更新到 2.0 版。 This seems to solve the problem.这似乎可以解决问题。

The API is using EF Core 3.1. API 使用的是 EF Core 3.1。 EF Core is using MARS(MultipleActiveResultSets). EF Core 正在使用 MARS(MultipleActiveResultSets)。 There seems to be a problem with Microsoft.Data.SqlClient version 1.0 when deployed on Linux and using MARS.在 Linux 上部署并使用 MARS 时,Microsoft.Data.SqlClient 版本 1.0 似乎存在问题。 EF Core is using by default v1. EF Core 默认使用 v1。

This might be related to EF Core exception when i send multiple requests #13452 :当我发送多个请求 #13452 时,这可能与 EF Core 异常有关:

I updated my project to ASP.NET Core 2.1 RTM.我将我的项目更新为 ASP.NET Core 2.1 RTM。 When I send multiple requests, i get this exception:当我发送多个请求时,我得到了这个异常:

 Exception has occurred: CLR/System.Data.SqlClient.SqlException An exception of type 'System.Data.SqlClient.SqlException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code: 'Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.ComponentModel.Win32Exception: Unknown error 258

@ajcvickers I found problem.The SQL Server host has received two updates: KB4338815 , KB4338824 . @ajcvickers 我发现了问题。SQL 服务器主机已收到两个更新: KB4338815KB4338824

Known issues in this update Restarting the SQL Server service may fail occasionally with the error, “Tcp port is already in use”.此更新中的已知问题 重新启动 SQL 服务器服务可能偶尔会失败,并出现错误“Tcp 端口已在使用中”。

When I removed these updates, my project worked without problem.当我删除这些更新时,我的项目运行没有问题。


Of course, this could also just be a deadlock scenario.当然,这也可能只是一个死锁场景。 To track this more easily, you might want to log both: very slow but successful queries and failing queries.为了更轻松地跟踪这一点,您可能希望同时记录:非常慢但成功的查询和失败的查询。

In a deadlock scenario, at least two queries are involved.在死锁场景中,至少涉及两个查询。 At least one would timeout, but the other could still be under the timeout threshold and then succeed once the first query got cancelled.至少一个会超时,但另一个可能仍低于超时阈值,然后在第一个查询被取消后成功。 So if you log both, you can trace the reason for the deadlock.因此,如果您同时记录两者,则可以追踪死锁的原因。


In any case, if you want to deal with issues like this in general, you might want to setup Connection Resiliency by using options.EnableRetryOnFailure() and probably lowering the command timeout value.在任何情况下,如果您想处理此类问题,您可能需要使用options.EnableRetryOnFailure()并可能降低命令超时值来设置连接弹性 This will retry failing operations.这将重试失败的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM