{"record":{"id":"fcdbc34fc181c35d","repo":"PowerShell/PowerShell","slug":"the-request-was-canceled-due-to-the-configured-ope-fcdbc3","errorCode":null,"errorMessage":"The request was canceled due to the configured OperationTimeout of {perReadTimeout.TotalSeconds} seconds elapsing","messagePattern":"The request was canceled due to the configured OperationTimeout of (.+?) seconds elapsing","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs","lineNumber":325,"sourceCode":"                        cts.Dispose();\n                        cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);\n                    }\n\n                    cts.CancelAfter(perReadTimeout);\n                    int bytesRead = await source.ReadAsync(buffer, cts.Token).ConfigureAwait(false);\n                    if (bytesRead == 0)\n                    {\n                        break;\n                    }\n\n                    await destination.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(false);\n                }\n            }\n            catch (TaskCanceledException ex)\n            {\n                if (cts.IsCancellationRequested)\n                {\n                    throw new TimeoutException($\"The request was canceled due to the configured OperationTimeout of {perReadTimeout.TotalSeconds} seconds elapsing\", ex);\n                }\n                else\n                {\n                    throw;\n                }\n            }\n            finally\n            {\n                cts.Dispose();\n                ArrayPool<byte>.Shared.Return(buffer);\n            }\n        }\n    }\n\n    internal static class StreamHelper\n    {\n        #region Constants\n","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/PowerShell/PowerShell/blob/3ff3c711bf54a18f8440f3c5190c3ac91cdc5852/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs#L307-L343","documentation":"Thrown by CopyToAsync during response-body streaming when a read within the copy loop exceeds perReadTimeout and the linked CancellationTokenSource cancels. Equivalent to the per-read timeout but on the streaming-copy path; cts.IsCancellationRequested distinguishes the timeout from an external cancellation.","triggerScenarios":"Streaming a response body to disk/pipe where an individual read in the copy loop stalls longer than perReadTimeout, while the overall operation is otherwise progressing.","commonSituations":"Slow/metered upstream during large file downloads; intermediate proxy buffering then pausing; high-latency or lossy links causing read stalls.","solutions":["Raise the per-read timeout for large/slow downloads","Stream to a resumable destination (file with Range requests) so a timeout can be retried from the last offset","Retry the whole request with backoff if the stall is transient","Move the download off the interactive request path to a background job"],"exampleFix":"# before\nInvoke-WebRequest -Uri $u -OutFile big.zip -TimeoutSec 10\n\n# after\nInvoke-WebRequest -Uri $u -OutFile big.zip -OperationTimeout (New-TimeSpan -Minutes 5)","handlingStrategy":"retry","validationCode":"$null","typeGuard":"null","tryCatchPattern":"try { Invoke-WebRequest -Uri $u -OutFile $f -OperationTimeout $ts } catch [System.TimeoutException] { Write-Warning 'Stream copy timed out; resuming.'; <# resume from offset or retry #> }","preventionTips":["Use a large enough per-read/operation timeout for big downloads","Stream to resumable destinations so timeouts can be retried without restarting"],"tags":["invoke-webrequest","timeout","streaming","download"],"backgroundTag":null,"analyzedSha":"3ff3c711bf54a18f8440f3c5190c3ac91cdc5852","analyzedAt":"2026-08-13T10:39:10.759Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}