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

Reading binary data asynchronously hangs execution #2276

Closed
mdzieg opened this issue Dec 18, 2023 · 11 comments
Closed

Reading binary data asynchronously hangs execution #2276

mdzieg opened this issue Dec 18, 2023 · 11 comments
Labels
customer-reported Duplicate This issue or pull request already exists

Comments

@mdzieg
Copy link

mdzieg commented Dec 18, 2023

Repro code can be found here: https://github.com/mdzieg/LBOTest/tree/main

Initialize database using SQL from readme. Update connection string in the code if needed.
Code inserts data file and then tries to load it.

When reading entity with binary data it hangs when using async method:

var att = await c.AttachmentData.FindAsync(1);

but works okay when using sync method:

var att = c.AttachmentData.Find(1);

This issue has its roots most likely in SqlClient library, although it was claimed fixed: #600

Include provider and version information

EF Core version: 8
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: WIN 11
IDE: N/A

@ajcvickers ajcvickers transferred this issue from dotnet/efcore Dec 18, 2023
@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 18, 2023

@mdzieg Did you try 5.2 preview 4?

@mdzieg
Copy link
Author

mdzieg commented Dec 19, 2023

@ErikEJ added <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0-preview4.23342.2" /> and tested, but no luck. It still hangs.

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 19, 2023

How do you load the 66 MB file?

@mdzieg
Copy link
Author

mdzieg commented Dec 19, 2023

How do you load the 66 MB file?

This POC uses my app database and I have data already in the table. I did not add data loading code to the POC, but can do so.

edit: @ErikEJ updated POC code, now it loads data file;

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 19, 2023

Thanks, duplicate of #593

@mdzieg
Copy link
Author

mdzieg commented Dec 19, 2023

Thanks, duplicate of #593

@ErikEJ It looks like a long issue originating in mid 2020. Is this something that is being fixed at the moment? You mentioned there "I have confirmed that the major improvement will be in 5.2 preview 4 and later" but using that lib version did not help in my case.

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 19, 2023

Your use case is very large binary objects, and the improvements are better for smaller binary objects.

Read the issue to understand the challenges involved, I do not think this is a high priority at the moment.

IMHO saving 66 MB binary objects in a database is an anti pattern. Use a file system for that.

@mdzieg
Copy link
Author

mdzieg commented Dec 19, 2023

Your use case is very large binary objects, and the improvements are better for smaller binary objects.

Read the issue to understand the challenges involved, I do not think this is a high priority at the moment.

IMHO saving 66 MB binary objects in a database is an anti pattern. Use a file system for that.

Seems it will not be fixed any time soon then.

Saving large binary objects to the database in most cases is an anti-pattern, I agree.

I did not expect such a basic operation to hang our application. Now we are aware of the problem and will avoid async code with LBO.

@Wraith2
Copy link
Contributor

Wraith2 commented Dec 19, 2023

Can you reproduce it without all the entity framework stuff? If you can get me a sql client only repro I'll take a look and see if there's something other than the known issues occurring here.

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 19, 2023

@Wraith2 I took the repro code and added this after the call to CreateData:

using var connection = new SqlConnection(connectionString);
connection.Open();
using (var command = connection.CreateCommand())
{
    command.CommandText = "SELECT TOP(1) Id, Data FROM nattachment.attachment";
    using var reader = command.ExecuteReader();
    while (reader.Read())
    {
        var key = reader.GetFieldValue<int>(0);
        var data = reader.GetFieldValue<byte[]>(1);
        Console.WriteLine($"Key: {key}, Data: {data.Length}");
    }
}

using (var command = connection.CreateCommand())
{
    command.CommandText = "SELECT TOP(1) Id, Data FROM nattachment.attachment";
    using var reader = await command.ExecuteReaderAsync();
    while (await reader.ReadAsync())
    {
        var key = await reader.GetFieldValueAsync<int>(0);
        var data = await reader.GetFieldValueAsync<byte[]>(1);
        Console.WriteLine($"Key: {key}, Data: {data.Length}");
    }
}

@JRahnama JRahnama added this to Needs triage in SqlClient Triage Board via automation Dec 19, 2023
@kf-gonzalez
Copy link

Closing as it is a duplicate of #593

SqlClient Triage Board automation moved this from Needs triage to Closed Dec 19, 2023
@kf-gonzalez kf-gonzalez added Duplicate This issue or pull request already exists and removed untriaged labels Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Duplicate This issue or pull request already exists
Projects
Development

No branches or pull requests

5 participants