Skip to content

Commit 7785751

Browse files
committed
Improve documentation on safe defaults
1 parent 94ea801 commit 7785751

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/Components/Server/src/Circuits/RemoteJSDataStream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static async ValueTask<RemoteJSDataStream> CreateRemoteJSDataStreamAsync(
4242
long totalLength,
4343
long maximumIncomingBytes,
4444
TimeSpan jsInteropDefaultCallTimeout,
45-
long pauseIncomingBytesThreshold,
46-
long resumeIncomingBytesThreshold,
47-
CancellationToken cancellationToken)
45+
long pauseIncomingBytesThreshold = -1,
46+
long resumeIncomingBytesThreshold = -1,
47+
CancellationToken cancellationToken = default)
4848
{
4949
// Enforce minimum 1 kb, maximum 50 kb, SignalR message size.
5050
// We budget 512 bytes overhead for the transfer, thus leaving at least 512 bytes for data

src/Components/Server/src/Circuits/RemoteJSRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void MarkPermanentlyDisconnected()
157157
_clientProxy = null;
158158
}
159159

160-
protected override async Task<Stream> ReadJSDataAsStreamAsync(IJSStreamReference jsStreamReference, long totalLength, long pauseIncomingBytesThreshold, long resumeIncomingBytesThreshold, CancellationToken cancellationToken)
160+
protected override async Task<Stream> ReadJSDataAsStreamAsync(IJSStreamReference jsStreamReference, long totalLength, long pauseIncomingBytesThreshold = -1, long resumeIncomingBytesThreshold = -1, CancellationToken cancellationToken = default)
161161
=> await RemoteJSDataStream.CreateRemoteJSDataStreamAsync(this, jsStreamReference, totalLength, _maximumIncomingBytes, _options.JSInteropDefaultCallTimeout, pauseIncomingBytesThreshold, resumeIncomingBytesThreshold, cancellationToken);
162162

163163
public static class Log

src/JSInterop/Microsoft.JSInterop/src/IJSStreamReference.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ public interface IJSStreamReference : IAsyncDisposable
2222
/// Opens a <see cref="Stream"/> with the <see cref="JSRuntime"/> for the current data reference.
2323
/// </summary>
2424
/// <param name="maxAllowedSize">Maximum number of bytes permitted to be read from JavaScript.</param>
25-
/// <param name="pauseIncomingBytesThreshold">The number of unconsumed bytes to accept from JS before blocking. A value of zero prevents JS from blocking, allowing .NET to receive an unlimited number of bytes.</param>
26-
/// <param name="resumeIncomingBytesThreshold">The number of unflushed bytes at which point JS stops blocking.</param>
25+
/// <param name="pauseIncomingBytesThreshold">
26+
/// The number of unconsumed bytes to accept from JS before blocking.
27+
/// Defaults to -1, which indicates use of the default <see cref="System.IO.Pipelines.PipeOptions.PauseWriterThreshold" />.
28+
/// Avoid specifying an excessively large value because this could allow clients to exhaust memory.
29+
/// A value of zero prevents JS from blocking, allowing .NET to receive an unlimited number of bytes.
30+
/// </param>
31+
/// <param name="resumeIncomingBytesThreshold">
32+
/// The number of unflushed bytes at which point JS stops blocking.
33+
/// Defaults to -1, which indicates use of the default <see cref="System.IO.Pipelines.PipeOptions.PauseWriterThreshold" />.
34+
/// Must be less than the <paramref name="pauseIncomingBytesThreshold"/> to prevent thrashing at the limit.
35+
/// </param>
2736
/// <param name="cancellationToken"><see cref="CancellationToken" /> for cancelling read.</param>
2837
/// <returns><see cref="Stream"/> which can provide data associated with the current data reference.</returns>
2938
ValueTask<Stream> OpenReadStreamAsync(long maxAllowedSize = 512000, long pauseIncomingBytesThreshold = -1, long resumeIncomingBytesThreshold = -1, CancellationToken cancellationToken = default);

src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,20 @@ protected internal virtual void ReceiveByteArray(int id, byte[] data)
215215
/// </summary>
216216
/// <param name="jsStreamReference"><see cref="IJSStreamReference"/> to produce a data stream for.</param>
217217
/// <param name="totalLength">Expected length of the incoming data stream.</param>
218-
/// <param name="pauseIncomingBytesThreshold">The number of unconsumed bytes to accept from JS before blocking. A value of zero prevents JS from blocking, allowing .NET to receive an unlimited number of bytes.</param>
219-
/// <param name="resumeIncomingBytesThreshold">The number of unflushed bytes at which point JS stops blocking.</param>
218+
/// <param name="pauseIncomingBytesThreshold">
219+
/// The number of unconsumed bytes to accept from JS before blocking.
220+
/// Defaults to -1, which indicates use of the default <see cref="System.IO.Pipelines.PipeOptions.PauseWriterThreshold" />.
221+
/// Avoid specifying an excessively large value because this could allow clients to exhaust memory.
222+
/// A value of zero prevents JS from blocking, allowing .NET to receive an unlimited number of bytes.
223+
/// </param>
224+
/// <param name="resumeIncomingBytesThreshold">
225+
/// The number of unflushed bytes at which point JS stops blocking.
226+
/// Defaults to -1, which indicates use of the default <see cref="System.IO.Pipelines.PipeOptions.PauseWriterThreshold" />.
227+
/// Must be less than the <paramref name="pauseIncomingBytesThreshold"/> to prevent thrashing at the limit.
228+
/// </param>
220229
/// <param name="cancellationToken"><see cref="CancellationToken" /> for cancelling read.</param>
221230
/// <returns><see cref="Stream"/> for the data reference represented by <paramref name="jsStreamReference"/>.</returns>
222-
protected internal virtual Task<Stream> ReadJSDataAsStreamAsync(IJSStreamReference jsStreamReference, long totalLength, long pauseIncomingBytesThreshold, long resumeIncomingBytesThreshold, CancellationToken cancellationToken)
231+
protected internal virtual Task<Stream> ReadJSDataAsStreamAsync(IJSStreamReference jsStreamReference, long totalLength, long pauseIncomingBytesThreshold = -1, long resumeIncomingBytesThreshold = -1, CancellationToken cancellationToken = default)
223232
{
224233
// The reason it's virtual and not abstract is just for back-compat
225234

src/JSInterop/Microsoft.JSInterop/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(this Microsoft.JS
3636
static Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, System.TimeSpan timeout, params object?[]? args) -> System.Threading.Tasks.ValueTask
3737
*REMOVED*static Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, params object![]! args) -> System.Threading.Tasks.ValueTask
3838
static Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(this Microsoft.JSInterop.IJSRuntime! jsRuntime, string! identifier, params object?[]? args) -> System.Threading.Tasks.ValueTask
39-
virtual Microsoft.JSInterop.JSRuntime.ReadJSDataAsStreamAsync(Microsoft.JSInterop.IJSStreamReference! jsStreamReference, long totalLength, long pauseIncomingBytesThreshold, long resumeIncomingBytesThreshold, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.IO.Stream!>!
39+
virtual Microsoft.JSInterop.JSRuntime.ReadJSDataAsStreamAsync(Microsoft.JSInterop.IJSStreamReference! jsStreamReference, long totalLength, long pauseIncomingBytesThreshold = -1, long resumeIncomingBytesThreshold = -1, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<System.IO.Stream!>!
4040
virtual Microsoft.JSInterop.JSRuntime.ReceiveByteArray(int id, byte[]! data) -> void
4141
virtual Microsoft.JSInterop.JSRuntime.SendByteArray(int id, byte[]! data) -> void
4242
Microsoft.JSInterop.JSDisconnectedException

0 commit comments

Comments
 (0)