Skip to content

SqlClient 6.0.1 DataReader hangs on trying to read 1 row with 150Mb value in nvarchar(max) column - consume huge amount of memory, and do not react to cancelationToken #3274

Closed
@AlexanderKot

Description

@AlexanderKot

Describe the bug

In app I am developing happens error as result it stored several huge strings in nvarchar(max) column - 150Mb json.
Then trying to read such record with DataReader application starts consume huge amount of memory and do not react to cancellation attempts using cancellationToken.

It looks like this
Image
On picture resource consumption by App with only 1 operation running - reading this row.
Trying to read 1 row with 150Mb column it consume up to 10G of mem.

Let assume app receive 150Mb from DB, and then convert it to 300Mb UTF16 string
What for it consume other 9.5Gb?

Data was saved to DB with same client, quick and with adequate resource consumption.

Trying to debug next state can be observed:
Image

In our app code execution stopped on await _reader.ReadAsync(cancellationToken)
and cancellationToken is activated by closing web page.

At this time control is in TP Worker thread processing read request

Image
There some cancellationToken token checked only at the beginning of operation and seems that is another token, as it is not activated.

Most of the time thread can be stopped in next methods called from SqlDataReader:

Image

Image

Expected behavior

  1. React to cancellation token
  2. Do read operation with adequate memory consumption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions