question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible bug: SqlDataReader.ReadAsync hangs and produces high garbage collection.

See original GitHub issue

Tested 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:closed
  • Created 4 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Wraith2commented, Sep 25, 2020

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.

1reaction
Wraith2commented, Sep 25, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found