Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of Memory issue when uploading large files #889

Closed
instriker opened this issue Oct 13, 2016 · 7 comments
Closed

Out of Memory issue when uploading large files #889

instriker opened this issue Oct 13, 2016 · 7 comments

Comments

@instriker
Copy link

When we are uploading the large files with RestSharp, we randomly get some OutOfMemory issues. This happens because RestSharp is using HttpWebRequest behind the scene, and the default value for AllowWriteStreamBuffering is true. This mean that the whole file are loaded in memory when doing the query, in case there are some redirections to be able to replay it. But If we are uploading a 500 mb file, its an issue.

What we would need is to be able to set the AllowWriteStreamBuffering to false, but there is no way right now to alter the AllowWriteStreamBuffering in the ConfigureWebRequest.

Something like this would be sufficient for our need:

var request = new RestRequest(Method.POST); request.AllowWriteStreamBuffering = false; request.Files.Add(new FileParameter // ...

@instriker
Copy link
Author

instriker commented Oct 25, 2016

Note : To be able to test the memory pressure of .Net vs RestSharp 105.2.3, here is how we tested it as there is an unreleased bug fix when using the .AddFile:

// In the current implementation of RestSharp, there is an issue when using AddFile with a writer.
// It doesn't set the ContentLength, which break the queries with System.Net.ProtocolViolationException as we are not uploading 
// the expected amount of bytes. It's fixed in an yet unreleased version, so we are using the Files.Add manually for now.
var request = new RestRequest(Method.POST);
request.Files.Add(new FileParameter
{
                Name = "file",
                Writer = outStream => inStream.CopyTo(outStream),
                FileName = fileName,
                ContentLength = inStream.Length,
});

@MistyKuu
Copy link

MistyKuu commented Apr 4, 2017

Any update on this? I'm having exactly the same issue and it seems to me reasonable to expose AllowWriteStreamBuffering either in RestClient or RestRequest. As far as I know there is no workaround. My use case it to send in parallel 100MB files and if AllowWriteStreamBuffering is true it will throw out of memory exception very often.

@nevergiveupc
Copy link

I encounter same issue and don't how to deal with

@AgentCoolDevil
Copy link

is it solved yet ????

@alexeyzimarev
Copy link
Member

@AgentCoolDevil you want to help? Do a pull request.

@Psypher9
Copy link
Contributor

Psypher9 commented Oct 1, 2018

Is anyone still getting this error on the latest version?

@alexeyzimarev
Copy link
Member

As @yvesmh rightfully mentioned in #1213, this issue can be solved by disabling the WebRequest write stream buffering. You can use the web request configuration on IRestClient to handle such cases.

client.ConfigureWebRequest(x => x.AllowWriteStreamBuffering = false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants