Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][websocket] Fix for Close Description validation #45536

Merged
merged 9 commits into from
Jan 5, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -463,24 +463,39 @@ public override void Abort()
Dispose();
}

public override async Task CloseAsync(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken)
public override Task CloseAsync(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken)
{
_writeBuffer = null;
ThrowIfNotConnected();
await CloseAsyncCore(closeStatus, statusDescription, cancellationToken).ConfigureAwait(continueOnCapturedContext: true);
}

private async Task CloseAsyncCore(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken)
{
ThrowOnInvalidState(State, WebSocketState.Connecting, WebSocketState.Open, WebSocketState.CloseReceived, WebSocketState.CloseSent);

WebSocketValidate.ValidateCloseStatus(closeStatus, statusDescription);

_tcsClose = new TaskCompletionSource();
_innerWebSocketCloseStatus = closeStatus;
_innerWebSocketCloseStatusDescription = statusDescription;
_innerWebSocket!.Invoke("close", (int)closeStatus, statusDescription);
await _tcsClose.Task.ConfigureAwait(continueOnCapturedContext: true);
try
{
ThrowOnInvalidState(State, WebSocketState.Connecting, WebSocketState.Open, WebSocketState.CloseReceived, WebSocketState.CloseSent);
}
catch (Exception exc)
{
return Task.FromException(exc);
}

return CloseAsyncCore(closeStatus, statusDescription, cancellationToken);
}

private Task CloseAsyncCore(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken)
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
_tcsClose = new TaskCompletionSource();
_innerWebSocketCloseStatus = closeStatus;
_innerWebSocketCloseStatusDescription = statusDescription;
_innerWebSocket!.Invoke("close", (int)closeStatus, statusDescription);
return _tcsClose.Task;
}
catch (Exception exc)
{
return Task.FromException(exc);
}
}

public override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string? statusDescription, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public async Task CloseAsync_CloseDescriptionIsMaxLength_Success(Uri server)

[OuterLoop("Uses external server")]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/45531", TestPlatforms.Browser)]
public async Task CloseAsync_CloseDescriptionIsMaxLengthPlusOne_ThrowsArgumentException(Uri server)
{
string closeDescription = new string('C', CloseDescriptionMaxLength + 1);
Expand Down