-
Notifications
You must be signed in to change notification settings - Fork 515
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
Upload Progress with ProgressMessageHandler Completes Unexpectedly #21537
Comments
@mandel-macaque can you have a look at this? |
Does look like the default size was wrongly set in mono long time ago. For what I can see, the code was moved with that max size value from the mono repo around 2019. I'll make sure we map this size with the one in the managed handler to make it more reasonable. |
@mandel-macaque Thanks for your response. I'm a little confused as to why it doesn't appear to be a commonly-seen problem? It would seem to apply to anyone performing uploads of files with significant size, and the workaround isn't incredibly obvious or straightforward. Also, we'd like to remove the workaround (platform-specific) code as soon as possible. Do you have any thoughts on when this change might be available? |
@tylersouthard we have had not many reports about this issue, I suspect it is because most of our users are uploading small files and they do not use the progress handler. The ideal solution would be to find a balance between using the NSData and a NSInputStream that makes sense. Unfortunately the Apple documentation has no pointers to the ideal memory limit in this scenario. One of my ideas is to use the same value used by the dotnet BCL. Both the HttpContent class and the MemoryStream class use a max value of int.MaxValue. You will also notice that HttpClient uses the HttpContent max value to ensure that MaxResponseContentBufferSize is not too big. Regarding the platform specific code, it is expected for an app developer to configure the native handler according to the platform, we can set some defaults that might make sense, but the app developer knows best. |
…CL classes. Fixes #21537 The MaxInputInMemory property is set by default to be long.MaxValue. This value is much larger than the one we can find in other BCL classes such as the HttpContent [max value](https://github.com/microsoft/referencesource/blob/master/System/net/System/Net/Http/HttpContent.cs#L20) and the MemoryStream [max value](https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs#L37). It is important to notice that the HttpContent.MaxValue is used to limit the value of the MaxResponseContentBufferSize property in the HttpClient. This means that by making this move we are following the rest of the BCL. Fixes #21537
@tylersouthard I have created an issue in the dotnet SDK, ideally we would want to expose an API for this kind of settings, that way we limit the amount of platform specific code you need, and maybe just change the values of the max size based on the platform. |
Apple platform
iOS
Framework version
net8.0-*
Affected platform version
.NET 8.0.302, VS Code 1.94.2, .NET MAUI extension v1.4.36
Description
When attempting to upload a file, it appears that the entirety of the file is first copied into memory, then uploaded. This causes two problems.
The issue here seems to point to similar problems, but the discussion centered around whether the content was coming in as a
MemoryStream
orFileStream
. This is aFileStream
, which I would not expect to enter memory all at once, since it should be streamed from disk to be uploaded in chunks.Steps to Reproduce
ProgressMessageHandler
reports progress in chunks, as expected, but the progress is much too fast to be the actual upload. They all happen within the same second or two.ProgressMessageHandler
track the actual upload, instead of presumably tracking the copy to memory.Did you find any workaround?
Adding a breakpoint to the
HttpSendProgress
event handler allows us to see NSUrlSessionHandler.cs in the call stack. That file appears to checkMaxInputInMemory
(line 503 currently). If we create a platform-specific shim to set this value to something much smaller thanlong.MaxValue
, the behavior is as expected.It doesn't seem possible that this workaround would be expected/required for what seems to be a common use case. Is that expectation correct?
Relevant log output
The text was updated successfully, but these errors were encountered: