Skip to content

Commit b8b7aab

Browse files
authored
Merge pull request #113 from kt81/fix-header-error
Prevent 'Expected magic value...' exception at failover
2 parents 94ef5d2 + 052641a commit b8b7aab

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Enyim.Caching/Memcached/PooledSocket.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ public async Task ReadAsync(byte[] buffer, int offset, int count)
292292
try
293293
{
294294
int currentRead = await _inputStream.ReadAsync(buffer, offset, shouldRead);
295-
if (currentRead == count || currentRead < 1)
295+
if (currentRead == count)
296296
break;
297+
if (currentRead < 1)
298+
throw new IOException("The socket seems to be disconnected");
297299

298300
read += currentRead;
299301
offset += currentRead;
@@ -330,8 +332,10 @@ public void Read(byte[] buffer, int offset, int count)
330332
try
331333
{
332334
int currentRead = _inputStream.Read(buffer, offset, shouldRead);
333-
if (currentRead == count || currentRead < 1)
335+
if (currentRead == count)
334336
break;
337+
if (currentRead < 1)
338+
throw new IOException("The socket seems to be disconnected");
335339

336340
read += currentRead;
337341
offset += currentRead;
@@ -437,4 +441,4 @@ public async Task WriteAsync(IList<ArraySegment<byte>> buffers)
437441
*
438442
* ************************************************************/
439443

440-
#endregion
444+
#endregion

0 commit comments

Comments
 (0)