Possible bug: SqlDataReader.ReadAsync hangs and produces high garbage collection.
See original GitHub issueTested on: System.Data.SqlClient versions “4.4.0”, “4.8.0” and “4.8.1”
I’m trying to read from a table which has 8 records. In ReadAsync it fetches the first 6 records quickly and hangs around 45 seconds to fetch the rest 2. During that 45 seconds time produces very high garbage collection.
The synchronous version on the other hand fetches the records immediately and there is no visible garbage collection.
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
{
...
}
vs.
while (reader.Read())
{
...
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
ADO dot what? | Rants of an ADO.NET Dev
Improving async performance for SqlDataReader ... In a managed application the Garbage Collector deals with memory management, ...
Read more >https://raw.githubusercontent.com/dotnet/samples/m...
This might be an old behavior or newly introduced bug. ... This includes collections like `Dictionary<K,V>` or `HashSet<T>` Assert.True(a.
Read more >Windows Community Toolkit | XAML Brewer, by Diederik Krols
In this article we showcase the latest and greatest version of the Radial Gauge control in a WinUI 3 Desktop Application.
Read more >The C# Programmer's Study Guide (MCSD)
Steps Involved in Garbage Collection . ... To the entire team at Apress, who made this book possible. ... to that complexity are...
Read more >Introducing .NET 4.5
Background Garbage Collection (GC) for the Server . ... language, the framework, and the IDE mean that developers have what they need to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That’s huge. Unless you actually need that as a string I strongly suggest using the GetTextReader overload in sequential mode, it’ll save you a lot of GC work.
Investigation stalled because there isn’t a complete repo, see “Can’t provide the db schema now.” above. If you have a self contained repo we can run then it can continue. Looking back at the report though It smells like long async strings to me and the answer is to not do that, fetch the string sync or use a textreader stream.