efcore: Invalid Operation, Error connection is closed. Azure Function with Azure SQL serverless
Client: Azure Function V3 on App Service Plan: (Linux) Premium v2 Codebase: .Net core 3.1 / Entity Framework Core 3.1.0 Database: Azure SQL (Serverless, Min 2 Cores/ Max 6 cores)
Intermittently but with high frequency getting error : Invalid Operation. Connection is closed. Below is complete error details
System.InvalidOperationException: Invalid operation. The connection is closed.
at Microsoft.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
at Microsoft.Data.SqlClient.TdsParser.WriteInt(Int32 v, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.Server.ValueUtilsSmi.SetCompatibleValue(SmiEventSink_Default sink, ITypedSettersV3 setters, Int32 ordinal, SmiMetaData metaData, Object value, ExtendedClrTypeCode typeCode, Int32 offset)
at Microsoft.Data.SqlClient.Server.ValueUtilsSmi.SetDataTable_Unchecked(SmiEventSink_Default sink, SmiTypedGetterSetter setters, Int32 ordinal, SmiMetaData metaData, DataTable value)
at Microsoft.Data.SqlClient.TdsParser.WriteSmiParameter(SqlParameter param, Int32 paramIndex, Boolean sendDefault, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject)
at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken)
EF Core version: 3.1.0 Database provider: (Microsoft.EntityFrameworkCore.SqlServer) UseSqlServer Target framework: (.NET Core 3.1) Operating system: Azure App Service Plan Premium v2 on Linux IDE: (e.g. Visual Studio 2019 16.3)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (7 by maintainers)
We have the same issue on AKS with kubernetes 1.13.10 with linux containers running EF Core 3.1 connected to Azure Sql Server. A little long running query works locally on Windows against the Azure Sql database, but the same call fails on the cluster with above error. As soon as I change to a syncronous call, it works in both cases.
You need to collect TCP network traces to figure out issues like these by looking into what communication is happening between Client and Server and what happens with connections or why do they close. Also compare the network traces from that of a regular Windows/Linux OS machine to capture any additional packet differences.
A driver issue is possible if the same problem is also reproducible outside any special environment, in a normal setup on Windows/Linux OS. Have you tried running the same app on your own desktop and does it fail the same way?