PowerShell/PowerShell · warning · TimeoutException
The request was canceled due to the configured OperationTime
Error message
The request was canceled due to the configured OperationTimeout of {perReadTimeout.TotalSeconds} seconds elapsing What it means
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.
Source
Thrown at src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs:325
cts.Dispose();
cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
}
cts.CancelAfter(perReadTimeout);
int bytesRead = await source.ReadAsync(buffer, cts.Token).ConfigureAwait(false);
if (bytesRead == 0)
{
break;
}
await destination.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(false);
}
}
catch (TaskCanceledException ex)
{
if (cts.IsCancellationRequested)
{
throw new TimeoutException($"The request was canceled due to the configured OperationTimeout of {perReadTimeout.TotalSeconds} seconds elapsing", ex);
}
else
{
throw;
}
}
finally
{
cts.Dispose();
ArrayPool<byte>.Shared.Return(buffer);
}
}
}
internal static class StreamHelper
{
#region Constants
View on GitHub (pinned to 3ff3c711bf)
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
Example fix
# before Invoke-WebRequest -Uri $u -OutFile big.zip -TimeoutSec 10 # after Invoke-WebRequest -Uri $u -OutFile big.zip -OperationTimeout (New-TimeSpan -Minutes 5)
Defensive patterns
Strategy: retry
Validate before calling
$null
Type guard
null
Try / catch
try { Invoke-WebRequest -Uri $u -OutFile $f -OperationTimeout $ts } catch [System.TimeoutException] { Write-Warning 'Stream copy timed out; resuming.'; <# resume from offset or retry #> } Prevention
- Use a large enough per-read/operation timeout for big downloads
- Stream to resumable destinations so timeouts can be retried without restarting
When it happens
Trigger: 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.
Common situations: Slow/metered upstream during large file downloads; intermediate proxy buffering then pausing; high-latency or lossy links causing read stalls.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- The request was canceled due to the configured OperationTime
- Unable to retrieve certificates because the thumbprint is no
- Access to the path '{0}' is denied.
AI-assisted analysis of PowerShell/PowerShell@3ff3c711bf (2026-08-13).
Data as JSON: /api/errors/fcdbc34fc181c35d.
Report an issue: GitHub.