Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Queries in Linux App Service: System.InvalidOperationException: Invalid operation. The connection is closed. #22463

Closed
simader opened this issue Sep 9, 2020 · 6 comments

Comments

@simader
Copy link

simader commented Sep 9, 2020

We want to host our backend in future in Linux App Services. Currently we are running the same code in Windows App Services.
However we encountered a problem with a bit more complicated query

System.InvalidOperationException: Invalid operation. The connection is closed.
   at Microsoft.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
   at Microsoft.Data.SqlClient.TdsParserStateObject.WriteBytes(ReadOnlySpan`1 b, Int32 len, Int32 offsetBuffer, Boolean canAccumulate, TaskCompletionSource`1 completion, Byte[] array)
   at Microsoft.Data.SqlClient.TdsParserStateObject.WriteByteArray(Byte[] b, Int32 len, Int32 offsetBuffer, Boolean canAccumulate, TaskCompletionSource`1 completion)
   at Microsoft.Data.SqlClient.TdsParser.WriteString(String s, Int32 length, Int32 offset, TdsParserStateObject stateObj, Boolean canAccumulate)
   at Microsoft.Data.SqlClient.TdsParser.TdsExecuteSQLBatch(String text, Int32 timeout, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean sync, Boolean callerHasConnectionLock, Byte[] enclavePackage)
   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.BeginExecuteReaderInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite)
   at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteReaderAsync(CommandBehavior behavior, AsyncCallback callback, Object stateObject)
   at Microsoft.Data.SqlClient.SqlCommand.<>c__DisplayClass173_0.<ExecuteReaderAsync>b__0(CommandBehavior commandBehavior, AsyncCallback callback, Object stateObject)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1](Func`4 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory`1.FromAsync[TArg1](Func`4 beginMethod, Func`2 endMethod, TArg1 arg1, Object state)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)

Steps to reproduce

this is the SQL Statement:

 var issueIds = issues.Select(c => c.Id).ToList();
                var directIssueReferences = await Context.IssueReference
                    .Where(r => r.IssueReferenceCategory != IssueReferenceCategory.AdditionalReference
                                && issueIds.Contains(r.IssueId))
                    .ToListAsync(token).ConfigureAwait(false);

results in a query

SELECT [i].[IssueReferenceId], [i].[CreationDate], [i].[IsDeleted], [i].[IssueId], [i].[IssueReferenceCategory], [i].[LastModified], [i].[ReferencedType], [i].[ReferencedTypeId]
FROM [IssueReference] AS [i]
WHERE ([i].[IsDeleted] <> CAST(1 AS bit)) AND (([i].[IssueReferenceCategory] <> 1) AND [i].[IssueId] IN ('640f2398-3b78-44a2-bf1b-4ba669f953a1', 'f0daec30-cc1f-4678-aa92-4be1412331be', '3f9d0435-eec3-447d-8342-4d00136e78bc', '3f16d086-a222-4f86-a4d5-4def8a0b7c2c', '0a52973b-45d8-4069-9f0c-4ec2d18c965a', 'de75a3d0-cc61-41d3-9ae1-5438bb8be8e5', 'd68e2552-1e49-4d72-814b-5ab856e7bf38', '61e2812c-957b-4ac6-a982-5e29c6634d41', 'bb85269e-7ef4-4c8a-becd-60dad4e7b1d5', '7a21b7f3-c564-4d87-984d-6bd7fd338221', '2cbdce71-0d0f-42b6-8aef-730c62ec9cb3', '216c2b81-fffd-45c7-bd3e-755ecfefe88a', '64ff892e-4cd9-4702-aed6-7bc205dbfff9', '2cafe702-e743-4e5a-8037-7ccbaa584c57', 'd4308e10-8f62-4788-ad19-7e9c7f64988c', '9712ed38-46f8-4127-94c8-8284c12e52a8', '3faff4a6-df00-4231-9633-83a85bb177d4', '79fedb82-731b-40b2-b277-84afb61e4c67', '573ec757-3fd4-493e-9c33-8594fd463394', '1bef8250-1393-4a4c-8419-8b157b2d1801', '7e921cc3-c4e6-4c8d-b137-8e25ee2e1f1f', '1b982a0b-74ea-4fdf-ba68-8f4f7d25acc5', '628101da-9649-48e0-8638-919c9f1816f7', 'bf766a20-99d3-4cae-bd91-971df9bad7b1', 'dee9cb3d-4ef1-43ad-8fe2-98145571fa34', '7f879a7b-5d09-43fb-bdaa-999fbc7a52bb', '8328b8d4-222a-422c-b18b-9aaacdce1cdb', 'c8f88201-b2ce-4838-acf8-9bdd796a9a4a', '25add696-13bb-4568-9f3e-b3418e975c6e', '2549d2ef-f32b-48d5-90a7-b5760184782f', 'af95a7a5-9f66-4664-b6cd-bf2ccb554038', '172b8473-229f-4d67-b31f-bf7de26f5dbd', 'ab113cdc-7ab3-4cd6-a003-c451e9da219f', 'e1ad898c-caec-418a-b0cb-c6c4524b1b37', '3b0b0aa9-9d83-488a-80d5-c9447261332c', '1934d530-c27b-4157-aceb-ce79f6f9f51e', 'ea80f43d-9464-42eb-b147-d73e0d4f4bd7', '33c65bcb-548e-4975-92a7-d7ab94dcd090', 'a95eb649-30f5-4967-9ca2-de4c3a03e15c', '6e3dd9c3-1d4c-49c1-b8da-e476b1c8a1f2', '17ffc0bb-6c10-4dfa-b5c0-e4862f4e0ce8', '3e942584-0284-4869-9a6a-e8457b3482da', 'ed7dfd9c-caff-48c8-97fc-ebc06a51fa9e', '282172bb-d4eb-4963-a8b0-f2e512c65280', 'de0b7eae-1aab-4234-acf3-fae37525b694', 'd70c6f8a-04e0-4538-9957-ff93218c89bc', 'd132d6db-aca2-49f8-9e27-ffa8b60d4caf', 'ef600cfc-6b64-46e4-9ad4-facca0cc5597', '46917a2d-35b0-4bb6-8e80-fc6dc9693010', '8aeb5de1-6f80-4c74-95a8-fe5388b34dd8', '85e8f8da-92d0-45ee-82ff-fed6829cd892', '9e2f4ce6-764b-475a-a31a-f38cd21d48cd', 'ad68bd4e-5003-42e6-af20-f56af963af7f', '1010e8e2-111f-4acf-b035-f7e9d59b16e7', '7532a15d-36c6-460e-9d7b-f8c9197adddb', '4f385734-a322-4cec-a68a-f9a5f1364ec3', 'fe6772b1-20ca-456c-be1f-edd63ae7a906', 'c1f9db12-f74f-4689-8c2b-e8291ed87257', '4b4b50ab-a1a6-4e1c-a6a8-e8bca10ac53f', '043d290e-bdb9-43a4-9781-eb0487eece5d', 'd99b694a-50d1-4cb7-ae7c-e56194c3e136', '06270321-f872-4864-8167-e1bb5001584d', '3e329ede-28ce-42f2-9040-de51ff9fe199', '7c7aecb9-3d75-474c-a9ee-dd9d20ebafcc', '70f5559c-1c71-4049-b57a-ded7fca5e5c2', '4e13f663-ed55-4e55-b167-df0532562e3b', 'd57c1ac4-0e29-4281-98c4-d9c34dc0593a', 'cd372493-0ae0-4669-a9db-db53556e69e5', '3683898a-59fc-4cbb-b901-dc62a34d3985', 'a5280f36-2d6b-4eae-9ceb-dce714d8803e', '39b3ffa3-fdbb-4b8d-b8c7-d5ffb1186295', 'dde05821-7999-4a46-9acf-d7cf8fa81ebc', '98c858c5-cb2b-4d6d-be3c-d4036b5c549c', '90cfa29f-42bc-4287-8ab6-d5643c60f31a', '76bdac3d-cbbc-4dd8-bac4-d5a81b7047ea', '599196c5-ad4a-4190-a9b2-cee78fc40f10', 'f71b3c57-0657-49a7-9dc0-cf1ff74d84ac', '88cc6d25-db19-4fdc-b547-d0d138d8da72', '10be6d54-496c-4c2e-a7fa-d13c324bf285', 'a1774144-2aa0-4d68-ab95-d168c465d583', '346816d2-cd42-44d9-828c-d211fb71c1e2', '3abfeb6f-6906-4646-9c88-cd8778c4e395', 'c5c8285a-4885-478f-9481-cd961728c721', 'd4d6e3d9-35ff-4fa4-a948-c5a40072cd82', '69c256d9-af26-4357-b78f-bf4486e4267c', '6d25b6c1-0440-4aae-b4c9-be0cda000051', '8ea1e76e-b016-4ee1-919c-c19c277effa3', '75809287-26b2-41d5-81b0-ba127a4fb218', 'c12ccaf1-c4c2-4c7d-9395-baf73fbb2e08', '9f3b34fd-8393-417e-830c-bb0bd48fbcd1', 'bd6d7869-a452-4568-9250-bb24e3115885', 'ddb2ce0e-f2f6-4de0-b3a9-b5196275230d', '2aeee79e-a043-4c55-a1d2-b5500f892208', '4b0b949b-0585-472e-9c04-b3034d1a15bc', '5921edc9-3e60-4f7e-bce5-acabed0429f0', '16e96741-c9e0-47ee-b907-ae70511c4706', 'e9a0337f-a8c1-4266-8b57-af9b2fa13f1c', 'a7837f11-be9a-4af2-93f1-b100d707e5ae', '44aa0d31-8120-435d-90cf-b139cf549589', '4f5fb3bc-0e6c-4ac0-a221-b1b23b61ea6a', '95a84a73-7002-4be5-8760-9d30361a019f', 'e4be5499-cce1-4151-af10-9d64b4be7f67', '53ee3965-9faf-44cf-80e7-9e7647730d71', 'ea661526-d114-4d89-81d3-9ee094ea8f86', '9c833d01-825a-4cff-a188-9fc6cc85db64', '8c4b0732-f462-44f7-b8bf-a1fe0ddacf71', 'd2ea03a4-54b8-498e-9366-a311b6ce1bf0', '46296518-1ff3-4f98-81c8-a5c33eba4878', '5ad8991d-cb34-42be-a643-a69933e5d051', '71dd33e6-d4da-46cc-a212-a91bce69e459', '08017019-a721-463d-b18a-9935fc8df7e0', '25b01bbd-b057-4d9b-8a06-98dfd2eb816a', 'bbc66761-56bf-4792-8538-97c8e1a95b50', '154d6a3d-5fdd-427d-aa66-93bfa779532b', 'afe35172-6183-411f-b2b7-93e5325976fb', '87e42a25-b06f-44f8-8678-9424a4d9c791', 'a00b3caa-cd61-44be-b46e-8fbd3ee72260', '41d38166-8b71-4236-aaab-8ee224204bae', 'db4e4b3f-4c79-4a69-a551-8b0be99215cb', '86688ba7-5ec4-4c8b-a03a-8c3aeb50cc2c', '1ced365b-12e9-4674-9617-8cd0b90535fd', 'ddafd8e7-e11e-4603-94ba-870a258708bd', 'ad378af2-b443-4b00-8d83-88c45b748932', 'a5a3ceb4-a76b-4740-87b0-89b62d2ddb0b', '6b5535b7-b9a5-4ce1-8005-89c3a7a0786e', '78409a4f-e6b3-492e-9c0e-84ca18abd46d', 'c8bac602-3e61-47b5-bbb8-836c6da7c8b8', 'c47ddb34-b384-4ab1-bc64-8263b9019fdc', '622a4e5b-24ed-436a-a7be-7be82427e94c', 'cd50b65a-41d1-4af4-b9eb-76f6bc20dd92', '8dbd2435-3058-490e-a05d-7772bfc2ffcd', 'b191bfd8-18f0-47b1-8c1e-77ef413a6a2b', 'b2524411-4fc4-4d11-816f-78f1ca2e30b2', '37eb02d8-646c-4db6-a8ca-79e58181da80', '235048f6-3e61-4403-ad80-7a4260da63b1', 'b1c0868e-53a4-4939-85cf-73a2c81da42e', 'ecdbe45b-f304-4824-aff9-6990f4f7b7b0', 'f5614e80-b863-4635-894f-69c5389d5827', '347d4f4b-36f9-4846-9c6b-6ce7c2d42fc1', 'db483b65-2662-4499-abb0-6d9231cd543a', 'a225e85a-f5d8-4f05-8a82-6fead57218b9', '7ff5c4e5-6967-4ba2-9250-5f0c9e375f2f', '0bd4c3e3-ca92-44e8-8286-6162c78ea5b5', '87a5290a-86c0-4c0d-9081-6164aaeffd7a', '16198c0a-7b48-4b02-bfed-64017e3ce894', 'bcd2ab5b-5be5-434b-90c4-66870a4aa693', 'f7d11cad-4afe-4499-b45f-668768812279', '66193fd3-5935-405c-986f-66904498d39d', 'c73f110f-4fad-41bc-9104-672508937e67', '3e0d04a4-00fa-436e-a1cc-5b535d0e6796', 'f578dc01-6c9f-4caf-83d2-59be11857655', 'f413d302-bfcc-491a-8863-586e2c72e1d6', '8a176bfe-4119-42a9-9ea6-52e85b5da254', '8a744272-8984-4657-b787-555bd01fbe2a', '7f63a4c6-c186-44f8-8754-5629d465fe35', '2f9ffcbb-b273-4868-870f-565f7551fab1', '4afd75c7-214b-47d5-9fff-57503a5c626e', '59ef4a63-43b6-49ed-b46c-4eccd8ab3707', '4a1b70d1-58a1-4e3d-8fac-4dc0f0062af8', '576c6e33-8aa3-4d34-af34-4b7445c42316', '2a1dee52-23f3-44b4-942a-4b0e9a143cf4', 'fcc79c81-4d8a-4f24-b960-4a613da538ad', 'eadd967f-21fa-4986-871d-469100148f74', '0af63aab-259a-4478-af99-46d57442c086', 'fc2f3089-e6d6-45eb-92eb-46e6d4a126d2', '503ce6d4-a87d-4a27-9c7f-4777146443ff', '87b38b37-63fa-4c88-88b4-48a1c256b092', '260a193e-062d-49e4-8098-48be5b3a0f96', '6d74741d-9af1-4c33-b2df-446c6b50b55f', '72192ff8-a6e7-4d26-a76d-45754dedc18a', '7cfac7de-1988-4022-b0b2-15fb765baf0e', 'd3ed8e2b-8d40-4390-9a44-17d1e558deb9', 'c7976918-e234-4520-a908-1b7cfff5d4e6', 'f6c63efb-7b9f-45d0-bff8-1c55b3156244', '081a00ab-fcd8-450d-ba8c-1f55ab6582b1', '55575c70-2c95-46c7-a92a-2898cafab5e3', '9745909a-9bc4-46dd-b8fb-30e7d2732d63', '0439391a-119f-48e5-b1c5-3eefa7e5b2e5', '23768ba2-e2db-465e-b9ed-3f1cdca992e6', 'bdff2219-2c2e-4e92-a21a-3b27f23d9858', '1c6b4d1c-4e5c-431d-ac6f-3c352f0d978d', '66d3d19b-3dec-42d4-b8e7-286492e1c697', '518070d7-f155-4a0c-9824-290a3b0dbfd0', '00f63f38-1940-4704-9045-2971f223adc0', 'ab67bb0a-d70f-48fa-bc1a-2a1a217f6cbd', '653eb3b7-83df-44ed-8aec-269b910a3a36', '7b7b9a49-1695-4cbf-94e7-244197e57abd', 'c921b487-dbac-4b9e-9c86-20b7e86c2263', '8239ec4c-9373-4d8b-87df-22de5797c070', 'a79971c1-15f8-4cde-9cf2-1fca4538b515', 'c4ae26df-6b81-4645-9000-1d4e1db65f7e', 'c7cbcec1-fa32-413f-86d3-1b003b807506', 'f3df3f8d-a063-4dd1-8130-1b3667235c72', '7a517469-b9bc-4da0-a250-1addd4d1498c', '5a1b72f6-0d23-40ef-b6e6-1a20888c4e0a', 'e50240d6-c41c-4aae-95a9-15e9230121bc', '1ab2d45a-cb3e-4e2e-9ad3-10673702f3f2', 

Further technical details

EF Core version: Entity Framework Core 3.1.10
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Linux AppService

@ajcvickers
Copy link
Member

@simader TDS exceptions indicate an issue with the underlying SqlClient provider. Please check if there is an existing issue on https://github.com/dotnet/SqlClient and if not, then file an issue there and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that they can investigate.

@ajcvickers
Copy link
Member

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@simader
Copy link
Author

simader commented Nov 11, 2020

Hello Together,

Can you please open this issue again.
Enclosed you can find now a sample:
EfCoreLinux.zip

When you add a valid SqlAzure Connection string and run it on a Linux Maschine (I tried build server or Azure App Service) you will get the System.InvalidOperationException: Invalid operation. The connection is closed.

I tested a contains with 2000 guids, this is working.

Please help.

@ajcvickers
Copy link
Member

@simader Can you post the full stack trace of the exception and any inner exceptions?

@ajcvickers ajcvickers reopened this Nov 11, 2020
@simader
Copy link
Author

simader commented Nov 11, 2020

at Microsoft.Data.SqlClient.SqlCommand.<>c.b__164_0(Task1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.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.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)
at App1.UnitTestProject1.WhereClauseTest.InternalTest(SampleContext context, Int32 amount) in /home/vsts/work/1/s/App1/App1.UnitTestProject1/WhereClauseTest.cs:line 85
at App1.UnitTestProject1.WhereClauseTest.TestWhereClauseWithManyIds_OnSqlServer() in /home/vsts/work/1/s/App1/App1.UnitTestProject1/WhereClauseTest.cs:line 53

@ajcvickers
Copy link
Member

Tracked by dotnet/SqlClient#792

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants