PowerShell/PowerShell · warning · TimeoutException
The request was canceled due to the configured…
Error message
The request was canceled due to the configured OperationTimeout of {readTimeout.TotalSeconds} seconds elapsing What it means
Thrown by the web cmdlet stream reader when a single ReadAsync call does not complete within the configured OperationTimeout. A linked CancellationTokenSource cancels after readTimeout; if the cancellation fires (cts.IsCancellationRequested), the TaskCanceledException is converted to a TimeoutException with the elapsed seconds in the message.
Solutions
- Increase -OperationTimeout / -TimeoutSec to tolerate slow streams
- Investigate the upstream server's response streaming (chunked encoding, buffering) and fix the stall
- Add retry with exponential backoff around the call for transient stalls
- If streaming huge payloads, switch to a streaming download approach that tolerates slow reads
Example fix
# before Invoke-WebRequest -Uri $u -TimeoutSec 5 # after Invoke-WebRequest -Uri $u -OperationTimeout (New-TimeSpan -Minutes 2)
Defensive patterns
Strategy: retry
Validate before calling
$null
Type guard
null
Try / catch
try { Invoke-WebRequest -Uri $u -OperationTimeout $ts } catch [System.TimeoutException] { Write-Warning 'Read timed out; retrying.'; <# retry w/ backoff #> } Prevention
- Size -OperationTimeout to the slowest expected server response
- Investigate streaming stalls on the upstream; retry transient timeouts with backoff
When it happens
Trigger: Invoke-WebRequest/Invoke-RestMethod against a slow server that stalls mid-response (the connection opens but bytes stop arriving), with a finite -OperationTimeout or -TimeoutSec.
Common situations: Overloaded or hung upstream servers; network brownouts; large response bodies where the server trickles data slower than the per-read timeout; reverse proxies/proxies that hold the connection without streaming.
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…
- Access to the path ' ' is denied.
- Unable to retrieve certificates because the thumbprint is…
AI-assisted analysis of PowerShell/PowerShell@3ff3c711bf (2026-08-13).
Data as JSON: /api/errors/9ac7d59b04fc2573.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs:281
{
internal static async Task<int> ReadAsync(this Stream stream, Memory<byte> buffer, TimeSpan readTimeout, CancellationToken cancellationToken)
{
if (readTimeout == Timeout.InfiniteTimeSpan)
{
return await stream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
}
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
try
{
cts.CancelAfter(readTimeout);
return await stream.ReadAsync(buffer, cts.Token).ConfigureAwait(false);
}
catch (TaskCanceledException ex)
{
if (cts.IsCancellationRequested)
{
throw new TimeoutException($"The request was canceled due to the configured OperationTimeout of {readTimeout.TotalSeconds} seconds elapsing", ex);
}
else
{
throw;
}
}
}
internal static async Task CopyToAsync(this Stream source, Stream destination, TimeSpan perReadTimeout, CancellationToken cancellationToken)
{
if (perReadTimeout == Timeout.InfiniteTimeSpan)
{
// No timeout - use fast path
await source.CopyToAsync(destination, cancellationToken).ConfigureAwait(false);
return;
}
byte[] buffer = ArrayPool<byte>.Shared.Rent(StreamHelper.ChunkSize);View on GitHub (pinned to 3ff3c711bf)