From 76b5090a0ac5e4546064bd544f9b438fa52f4536 Mon Sep 17 00:00:00 2001 From: Stephen Just Date: Wed, 19 Aug 2020 10:47:19 -0700 Subject: [PATCH] Avoid unnecessary exception in TimeoutStream (#1015) 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. --- Lib/WindowsRuntime/Core/TimeoutStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/WindowsRuntime/Core/TimeoutStream.cs b/Lib/WindowsRuntime/Core/TimeoutStream.cs index ccff9e213..81008b7b6 100644 --- a/Lib/WindowsRuntime/Core/TimeoutStream.cs +++ b/Lib/WindowsRuntime/Core/TimeoutStream.cs @@ -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 { @@ -229,7 +229,7 @@ private void UpdateReadTimeout() private void UpdateWriteTimeout() { - if (this.wrappedStream.CanTimeout) + if (this.wrappedStream.CanTimeout && this.wrappedStream.CanWrite) { try {