From 052641a5b9268efb05af20d500b0ab31c2c72411 Mon Sep 17 00:00:00 2001 From: kt81 Date: Thu, 16 May 2019 14:13:10 +0900 Subject: [PATCH] Prevent 'Expected magic value...' exception when the peer memcached server is down with binary protocol --- Enyim.Caching/Memcached/PooledSocket.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Enyim.Caching/Memcached/PooledSocket.cs b/Enyim.Caching/Memcached/PooledSocket.cs index ce43c95e..fb5a2232 100755 --- a/Enyim.Caching/Memcached/PooledSocket.cs +++ b/Enyim.Caching/Memcached/PooledSocket.cs @@ -292,8 +292,10 @@ public async Task ReadAsync(byte[] buffer, int offset, int count) try { int currentRead = await _inputStream.ReadAsync(buffer, offset, shouldRead); - if (currentRead == count || currentRead < 1) + if (currentRead == count) break; + if (currentRead < 1) + throw new IOException("The socket seems to be disconnected"); read += currentRead; offset += currentRead; @@ -330,8 +332,10 @@ public void Read(byte[] buffer, int offset, int count) try { int currentRead = _inputStream.Read(buffer, offset, shouldRead); - if (currentRead == count || currentRead < 1) + if (currentRead == count) break; + if (currentRead < 1) + throw new IOException("The socket seems to be disconnected"); read += currentRead; offset += currentRead; @@ -437,4 +441,4 @@ public async Task WriteAsync(IList> buffers) * * ************************************************************/ -#endregion \ No newline at end of file +#endregion