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

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())
{
...
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

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.

Thanks for the repro @aliveli186 .

The new home for SqlClient driver issues is “dotnet/sqlclient” repository, we will investigate and get back to you!

@cheenamalhotra this might be worth moving