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
Invoke-RestMethod fails on very large files #4129
Comments
Didn't get a repro on Win10 nor Ubuntu16.04. Might be Mac specific. Memory usage seemed reasonable on Windows/Linux (less than 64MB on Windows and 4.3MB on Linux). |
I am using Windows 10 and Powershell 5.1. Anything over 2 GB gives me "Invoke-RestMethod : Stream was too long.". |
Hum! Does a 10GB file download should be handle using FTP protocol? I can't recall seen downloading an 10GB installation application using http/https protocol. :) |
@JoelMiller74 for Windows PowerShell 5.1 issues, please use the Windows PowerShell UserVoice. This repo is for PowerShell Core (6.0.0 and newer). We use a different API and different underlying architecture in PowerShell Core than was use in Windows PowerShell. Issues with downloads in 5.1 would likely not translate to problems in 6.0.1 (as in, the same error message may be due to different causes). |
@SteveL-MSFT I'm no expert on performance tuning, but It seems to me we should be calling PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs Lines 299 to 316 in c1c5344
The chunk size is 10,000 bytes so flushing every loop is probably not ideal, but, waiting until the end of the 10GB file does some funky stuff with RAM. Can you ping someone who can provide me with some guidance on this? |
@daxian-dbw would be best to provide guidance here although he's currently on vacation Even thought we have a separate timer now for writing progress to the screen, it seems overkill to update progress every chunk. Seems like we can solve two problems by updating progress and flushing the buffer every N milliseconds (or seconds?). |
Thanks! |
The exception is actually thrown from Here is the stack trace:
For a 64-bit program, the memory limit for a single .NET object is 2GB, unless you enable <configuration>
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>
</configuration> For a 32-bit program, the memory limit for a single .NET object is 512MB. So the The |
When I was working on optimizing the progress bar I found that WriteProgress doesn't have overhead - performance problem was only in writing on screen. @daxian-dbw and @lzybkr helped me to find optimal solution with flushing by timer every 200 ms. I don't think that we can do something else with the API. If we want be better we should re-design the progress bar API. Currently we do tons extra allocations. As for |
@iSazonov for 6.1, we will need to move to dotnetcore 2.1 for other reasons anyways (like full ARM support...) |
@markekraus We talked about this issue during the PS Summit where Here are my testing results: Name Value
---- -----
PSVersion 6.2.0
PSEdition Core
GitCommitId 6.2.0
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
|
Yes, see my previous comment #4129 (comment). It depends on a |
I am very curious to understand how the behavior of Invoke-RestMethod differs from Invoke-WebRequest in, more specific to handling large files (upload or download) as @tnieto88 shows. I have a PowerShell advanced function that has worked for quite a long time using .NetClientFramework 4.6 and newer API, in which it uses the I am able to reproduce this on a Windows 10 PC: Name Value
---- -----
PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
[PS] C:\Users\user> dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Is there any way to handle this correctly in PowerShell 6/PowerShellCore 6? |
I have done some further tests, and this looks like it is a .NetCore issue with |
I tried 7.0 Preview5 without any issue: Invoke-WebRequest -Uri https://images-dl.endlessm.com/release/3.7.3/eos-amd64-amd64/th/eos-eos3.7-amd64-amd64.191024-140039.th.iso -OutFile C:\temp\q.txt It was 9.4 Gb and was long but no memory issues and no exceptions. |
@iSazonov |
@daxian-dbw Thanks for remainder! It seems BufferingStreamReader class has an issue. Also I discovered that Ctrl-C doesn't work in Invoke-RestMethod for the large file download scenario. So I pulled a PR to resolve both issues. |
🎉This issue was addressed in #11095, which has now been successfully released as Handy links: |
It's nice to see this is being fixed in PowerShell Core. But, considering that |
@ChrisLynchHPE .Net team moved to HttpClient in .Net Core 3.0/3.1 and PowerShell 7.0 was released with the change. I am afraid that this was an inevitable breaking change. |
File transfer using API's is very common. So it is extremely frustrating to see breaking changes with no guidance on how to handle this going forward, beyond "well, just move to an async method class like |
@ChrisLGardner Please open new issue to discuss your scenario and reference the issue. |
It seems
Invoke-RestMethod
fails to download very large files, probably due to not enough memory.Steps to reproduce
Expected behavior
Very large files should be downloaded without issues.
Actual behavior
Environment data
Mac OS X 10.12.5
The text was updated successfully, but these errors were encountered: