Description
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
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:
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
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:
Expected behavior
- React to cancellation token
- Do read operation with adequate memory consumption.