-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Invoke-WebRequest and Invoke-RestMethod: Rename TimeoutSec to ConnectionTimeoutSeconds (with alias) and add OperationTimeoutSeconds #19558
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-WebRequest and Invoke-RestMethod: Rename TimeoutSec to ConnectionTimeoutSeconds (with alias) and add OperationTimeoutSeconds #19558
Conversation
31e3204
to
ab2ae01
Compare
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebRequestSession.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs
Show resolved
Hide resolved
73de5c3
to
25118fc
Compare
...ft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebResponseObject.Common.cs
Outdated
Show resolved
Hide resolved
5aaa286
to
6b41734
Compare
82ab2b6
to
6e34b1b
Compare
Reopening - accidentally force-pushed empty commits after a squash merge. |
dc09298
to
5294e9b
Compare
abe622a
to
53c1dc0
Compare
...erShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as far as the code.
@PowerShell/powershell-maintainers Is this a breaking change because public interfaces to a cmdlet was changed?
The changes seem significant with regard to memory handling. We should consider running performance testing before and after the change. Especially for downloading large files (at least 200MiB). This scenario is already slow, any performance regression may make the feature unusable. I don't see anything particularly bad, but we should test for the unexpected. |
I urge MSFT team to look at this carefully. |
53ae00d
to
62fa4cd
Compare
@PowerShell/wg-powershell-cmdlets reviewed this, we agree with the added functionality. However, we suggest renaming |
Setting to WIP while I address WG recommendations. |
…tSeconds TimeoutSec becomes ConnectionTimeoutSeconds and has same behaviour as before. OperationTimeoutSeconds specifies the maximum allowed time between reads from the network when streaming http response messages. The default for both items is to have no timeout. Co-Authored-By: CarloToso <105941898+CarloToso@users.noreply.github.com>
6b78f78
to
f667241
Compare
Ok, I have finished updating as per recommendations. I also did some minor refactoring of the timeout calculation code to share the conversion from integer seconds to a TimeSpan between the two timeouts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change! Overall, looks good, but one comment on the fully qualified error id.
test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
Outdated
Show resolved
Hide resolved
…o-ConnectTimeoutSec-and-alias-to-TimeoutSec-and-add-NetworkTimeoutSec-timeout
…eoutSec-and-alias-to-TimeoutSec-and-add-NetworkTimeoutSec-timeout
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
1 similar comment
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
@stevenebutler Thanks for your contribution! |
🎉 Handy links: |
PR Summary
This renames
-TimeoutSec
parameter (with alias to old parameter name) to-ConnectionTimeoutSeconds
and adds-OperationTimeoutSeconds
parameter to bothInvoke-WebRequest
andInvoke-RestMethod
commands.-TimeoutSec
becomes-ConnectionTimeoutSeconds
and is aliased with-TimeoutSec
and has same behaviour as before. That is, it is the timeout that applies from just prior to sending a web request to receiving the response headers.-OperationTimeoutSeconds
specifies the maximum allowed time between reads from the network when streaming http response content.The default for both items is to have no timeout.
close #12249
close #16122
close #19519
PR Context
There are reports that when a network stream goes away and the OS doesn't or is unable to notify PowerShell that the network stream has been lost that PowerShell hangs forever in
Invoke-WebRequest
/Invoke-RestMethod
on stalled response streams.A previous PR made it possible to use CTRL-C to terminate this, but there was no way to have PowerShell timeout after a period of network inactivity in batch scenarios. This PR adds the timeout. The timeout applies to inter-stream reads, and not to the stream time as a whole. Therefore setting the
-OperationTimeoutSeconds
to 30 seconds means that any delay of longer than 30 seconds between reading data from the stream will terminate the request. However a large file that takes several minutes to download will not terminate unless the stream stalls for more than 30 seconds.The default of 0 for
-ConnectionTimeoutSeconds
and-OperationTimeoutSeconds
means no timeout applies as per request by WG noted in #19519. Any value less than 0 for-OperationTimeoutSeconds
is also treated as no timeout.Performance Comparison
The following benchmark was used to assess performance implications of this PR over 7.3.4 vanilla using a local dotnet minimal API with a static array of bytes being returned by the website (source below).
All tests were run on a HP laptop with 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz 2.70 GHz and 16 GB memory. Note the dotnet web server and the client application were tested over HTTP on the same laptop over localhost interface.
Note: testing was done on an earlier iteration before renaming and minor refactoring of timeout handling.
The benchmark web server was built in Release configuration and run as an executable.
My conclusions from these results are:
-OperationTimeoutSeconds
parameter isn't used-OperationTimeoutSeconds
parameter is used but is still favourable when compared to curl performance. This is likely attributable to the work spent resetting the timeout on the cancellation token before each network read.curl
when it was significantly slower in the 7.3.4 release.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).