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][websockets] Support for CloseOutputAsync #47906

Merged
merged 47 commits into from
Feb 11, 2021
Merged

[browser][websockets] Support for CloseOutputAsync #47906

merged 47 commits into from
Feb 11, 2021

Conversation

kjpou1
Copy link
Contributor

@kjpou1 kjpou1 commented Feb 5, 2021

Note this relies on PR : #45827

  • Add support for CloseOutputAsync
  • Remove [ActiveIssue("https://github.com/dotnet/runtime/issues/45468", TestPlatforms.Browser)]
  • Add more tests

Fix #46909
Fix #45468
Fix #45674
Fix #45586
Close #46983

Comments from parent PR:

Multiple fixes for Abort.

There are multiple failures with the Abort tests causing some tests to:

  • Never end

  • Multiple GC calls that end in running out of memory.

  • Some failures are expected to fail with specific WebSocketError codes:

Error codes that are not correct tend to be when websockets tests are looking for specific error codes and messages when the browser returns NativeError and the websocket native error code instead.

failed: WebSocket is closed before the connection is established.

These need to be marked correctly and or caught and wrapped correctly.

Assert.Equal() Failure
  info: Expected: Aborted
  info: Actual:   Closed

Fixes for these should also fix some, note not all, of the memory runtime errors as per issue: #45586


Fix tests that were failing when expecting CloseSent as a valid state.

// fail: [FAIL] System.Net.WebSockets.Client.Tests(server: ws://corefx-net-http11.azurewebsites.net/WebSocket/EchoWebSocket.ashx)
//   info: Assert.Throws() Failure
//   info: Expected: typeof(System.OperationCanceledException)
//   info: Actual:   typeof(System.Net.WebSockets.WebSocketException): The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseSent'

Tests are intermittently failing with System.OperationCanceledException : The operation was canceled.

Added ActiveIssue for these two tests. #46909

It seems that sometimes the default timeout is not enough for browser so it is extended for browser environments
See issue https://github.com/dotnet/runtime/issues/46909

Further addressed in #47906


SendReceive_PartialMessageBeforeCompleteMessageArrives_Success which describes the test as Ask the remote server to echo back received messages without ever signaling "end of message". This test hangs as javascript fetch does not support this functionality.

See issue #46983 for more detailed description and native javascript tests.


Associate PR's: #44666 and #45470

Close #45586
Fix #45674

kjpou1 and others added 30 commits December 9, 2020 11:23
example from tests:

```
Assert.Equal() Failure
  info: Expected: Aborted
  info: Actual:   Closed
```
- This was causing a never ending Task when aborted after a Close already executed.
- Never ended which was a cause of memory errors after left running.
- See also #45586
- Exception text not sent correctly.  This test was expecting 'Aborted'.
- Mismatched expected exception messages
- Make sure the connection is torn down.
- Multiple GC calls that end in running out of memory fixed.  #45586

```
//  [FAIL] System.Net.WebSockets.Client.Tests.CancelTest.ReceiveAsync_AfterCancellationDoReceiveAsync_ThrowsWebSocketException(server: ws://corefx-net-http11.azurewebsites.net/WebSocket/EchoWebSocket.ashx)
//   info: Assert.Equal() Failure
//   info:                                  ↓ (pos 39)
//   info: Expected: ··· an invalid state ('Aborted') for this operation. Valid state···
//   info: Actual:   ··· an invalid state ('Open') for this operation. Valid states a···
//   info:                                  ↑ (pos 39)

```
…browser-websocket-abort-fixes

# Conflicts:
#	src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/BrowserWebSocket.cs
- Update tests that are resolved.
```
// fail: [FAIL] System.Net.WebSockets.Client.Tests(server: ws://corefx-net-http11.azurewebsites.net/WebSocket/EchoWebSocket.ashx)
//   info: Assert.Throws() Failure
//   info: Expected: typeof(System.OperationCanceledException)
//   info: Actual:   typeof(System.Net.WebSockets.WebSocketException): The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseSent'
```
- Fix the clean up of the task and set or cancel the task cleanly.
- intermittently failing with System.OperationCanceledException : The operation was canceled.
…tly failing with System.OperationCanceledException : The operation was canceled.

- This was an ActiveIssue #46909 but extending the time seems to do the job.
- [browser][websocket] Hang with responses without ever signaling "end of message"
- [ActiveIssue("#46983", TestPlatforms.Browser)]  // JS Fetch does not support see issue
- Fix for those browsers that do not set Close and send an onClose event in certain instances i.e. firefox and safari.
- Chrome will send an onClose event and we tear down the websocket there.  Other browsers need to be handled differently.
…ases

As per comments
- We clear all events on the websocket (including onClose),
- call websocket.close()
- then call the user provided onClose method manually.
@kjpou1 kjpou1 requested a review from wfurt February 9, 2021 11:05
@kjpou1
Copy link
Contributor Author

kjpou1 commented Feb 9, 2021

/azp run runtime-libraries-mono outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, mentioned a couple of nits.

…st.cs

Co-authored-by: Larry Ewing <lewing@microsoft.com>
@kjpou1 kjpou1 merged commit 42009d1 into dotnet:master Feb 11, 2021
@kjpou1 kjpou1 deleted the wasm-browser-websocket-CloseOutputAsync branch February 12, 2021 04:29
@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.