Skip to content

Commit bc6b2d8

Browse files
committed
CSHARP-1876: Throw TimeoutException from BlockingMemoryStream is _spinWaitTimeout expires.
1 parent 45d5fdb commit bc6b2d8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/MongoDB.Driver.Core.Tests/Core/Helpers/BlockingMemoryStream.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public override long Position
7676

7777
public override int Read(byte[] buffer, int offset, int count)
7878
{
79-
SpinWait.SpinUntil(() => Length - Position >= count, _spinWaitTimeout);
79+
if (!SpinWait.SpinUntil(() => Length - Position >= count, _spinWaitTimeout))
80+
{
81+
throw new TimeoutException();
82+
}
83+
8084
lock (_lock)
8185
{
8286
return base.Read(buffer, offset, count);
@@ -85,7 +89,10 @@ public override int Read(byte[] buffer, int offset, int count)
8589

8690
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
8791
{
88-
await Task.Run(() => { SpinWait.SpinUntil(() => Length - Position >= count, _spinWaitTimeout); });
92+
if (!(await Task.Run(() => SpinWait.SpinUntil(() => Length - Position >= count, _spinWaitTimeout))))
93+
{
94+
throw new TimeoutException();
95+
}
8996

9097
lock (_lock)
9198
{

0 commit comments

Comments
 (0)