Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Avoid unnecessary exception in TimeoutStream (#1015)
Browse files Browse the repository at this point in the history
Underlying stream implementation may throw if we try to set a read/write timeout on a non-readable or non-writable stream. Add an additional check to prevent this exception from being thrown.

Since this gets hit on every blob read, the impact is fairly significant for services which download many blobs.
  • Loading branch information
stephenjust authored Aug 19, 2020
1 parent 4b2db79 commit 76b5090
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/WindowsRuntime/Core/TimeoutStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void StopTimeout(CancellationTokenSource source, bool dispose)

private void UpdateReadTimeout()
{
if (this.wrappedStream.CanTimeout)
if (this.wrappedStream.CanTimeout && this.wrappedStream.CanRead)
{
try
{
Expand All @@ -229,7 +229,7 @@ private void UpdateReadTimeout()

private void UpdateWriteTimeout()
{
if (this.wrappedStream.CanTimeout)
if (this.wrappedStream.CanTimeout && this.wrappedStream.CanWrite)
{
try
{
Expand Down

0 comments on commit 76b5090

Please sign in to comment.