Skip to content

Commit

Permalink
RavenDB-23065 - check the cancellationToken for each call to Read or …
Browse files Browse the repository at this point in the history
…Write
  • Loading branch information
grisha-kotler committed Dec 9, 2024
1 parent 1b6a831 commit f16c875
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Raven.Client/Util/StreamWithTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ private async Task<int> ReadAsyncWithTimeout(byte[] buffer, int offset, int coun
_readCts?.Dispose();
_readCts = GenerateCancellationTokenWithTimeout(_readTimeout, cancellationToken);
}
}

#if DEBUG
if (_requestReadCts != cancellationToken)
throw new InvalidOperationException("The cancellation token was changed during the request");
if (_requestReadCts != cancellationToken)
throw new InvalidOperationException("The cancellation token was changed during the request");
#endif
}

var read = await _stream.ReadAsync(buffer, offset, count, _readCts.Token).ConfigureAwait(false);
_totalRead += read;
Expand Down Expand Up @@ -252,12 +252,12 @@ private Task WriteAsyncWithTimeout(byte[] buffer, int offset, int count, Cancell
_writeCts.Dispose();
_writeCts = GenerateCancellationTokenWithTimeout(_writeTimeout, cancellationToken);
}
}

#if DEBUG
if (_requestWriteCts != cancellationToken)
throw new InvalidOperationException("The cancellation token was changed during the request");
if (_requestWriteCts != cancellationToken)
throw new InvalidOperationException("The cancellation token was changed during the request");
#endif
}

return _stream.WriteAsync(buffer, offset, count, _writeCts.Token);
}
Expand Down

0 comments on commit f16c875

Please sign in to comment.