Skip to content

Commit 92b8bde

Browse files
author
rstam
committed
CSHARP-717: Fix regression where reading from a socket that has been closed by the server is now hanging instead of throwing an EndOfStreamException.
1 parent 2b69d85 commit 92b8bde

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

MongoDB.Bson/IO/ByteArrayBuffer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ public void LoadFrom(Stream stream, int count)
275275
while (count > 0)
276276
{
277277
var bytesRead = stream.Read(_bytes, _sliceOffset + position, count);
278+
if (bytesRead == 0)
279+
{
280+
throw new EndOfStreamException();
281+
}
278282
position += bytesRead;
279283
count -= bytesRead;
280284
}

MongoDB.Bson/IO/ByteBufferFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public static IByteBuffer LoadFrom(Stream stream)
7878
while (count > 0)
7979
{
8080
var bytesRead = stream.Read(lengthBytes, offset, count);
81+
if (bytesRead == 0)
82+
{
83+
throw new EndOfStreamException();
84+
}
8185
offset += bytesRead;
8286
count -= bytesRead;
8387
}

MongoDB.Bson/IO/MultiChunkBuffer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ public void LoadFrom(Stream stream, int count)
351351
var chunkRemaining = _chunkSize - chunkOffset;
352352
var bytesToRead = (count <= chunkRemaining) ? count : chunkRemaining;
353353
var bytesRead = stream.Read(_chunks[chunkIndex].Bytes, chunkOffset, bytesToRead);
354+
if (bytesRead == 0)
355+
{
356+
throw new EndOfStreamException();
357+
}
354358
position += bytesRead;
355359
count -= bytesRead;
356360
}

0 commit comments

Comments
 (0)