簡體   English   中英

Azure SQL 單個數據庫 DTU 超時過期錯誤

[英]Azure SQL Single Database DTU Timeout Expired Error

我用的是Azure SQL 單庫DTU采購model。 平均負載似乎低於 10%。 有時我會收到一個錯誤,現在幾乎每天都在發生。 我正在使用 EF Core 3.1 進行數據庫訪問。 該數據庫是從使用 ASP.NET 內核 3.1 構建的 API 訪問的,並部署在 Linux Z3A580F1402293867F AppF 服務上。
錯誤是:
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

堆棧跟蹤:

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)

知道是什么原因造成的嗎? 或者我怎樣才能找到導致問題的原因?

我將 nuget package Microsoft.Data.SqlClient 更新到 2.0 版。 這似乎可以解決問題。

API 使用的是 EF Core 3.1。 EF Core 正在使用 MARS(MultipleActiveResultSets)。 在 Linux 上部署並使用 MARS 時,Microsoft.Data.SqlClient 版本 1.0 似乎存在問題。 EF Core 默認使用 v1。

當我發送多個請求 #13452 時,這可能與 EF Core 異常有關:

我將我的項目更新為 ASP.NET Core 2.1 RTM。 當我發送多個請求時,我得到了這個異常:

 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 我發現了問題。SQL 服務器主機已收到兩個更新: KB4338815KB4338824

此更新中的已知問題 重新啟動 SQL 服務器服務可能偶爾會失敗,並出現錯誤“Tcp 端口已在使用中”。

當我刪除這些更新時,我的項目運行沒有問題。


當然,這也可能只是一個死鎖場景。 為了更輕松地跟蹤這一點,您可能希望同時記錄:非常慢但成功的查詢和失敗的查詢。

在死鎖場景中,至少涉及兩個查詢。 至少一個會超時,但另一個可能仍低於超時閾值,然后在第一個查詢被取消后成功。 因此,如果您同時記錄兩者,則可以追蹤死鎖的原因。


在任何情況下,如果您想處理此類問題,您可能需要使用options.EnableRetryOnFailure()並可能降低命令超時值來設置連接彈性 這將重試失敗的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM