Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Large response outofmem fix #564

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

megasuperlexa
Copy link

@megasuperlexa megasuperlexa commented Dec 23, 2024

I got a situation when my multi-GB response that I was reading asynchronously got interrupted with an error code. But unfortunately, the library attempts to deserialize the entire response in memory during ReadAsStringAsync hoping to obtain error text, which results in OOM.
The fix employs fixed length buffer to do the same and falls back to a pre-arranged exception in case something goes wrong.

@DarkWanderer
Copy link
Owner

Greetings. Thank you for your contribution. Can you add a test for this exception handling? (e.g. using mocking)

try
{
await response.Content.LoadIntoBufferAsync(4096);
var stream = (MemoryStream)await response.Content.ReadAsStreamAsync();
Copy link
Owner

@DarkWanderer DarkWanderer Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the cast to MemoryStream for?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants