Skip to content

Add WebSocketStream #114363

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

Closed
wants to merge 1 commit into from
Closed

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Apr 8, 2025

Closes #111217

@ghost
Copy link

ghost commented Apr 8, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost
Copy link

ghost commented Apr 8, 2025

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

if (WebSocket.State is WebSocketState.Open)
{
// There's no synchronous close, so we're forced to do sync-over-async.
WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None).GetAwaiter().GetResult();
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this cause deadlocks in UI contexts such as WPF and Windows Forms?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not as long as everything within CloseOutputAsync uses ConfigureAwait(false)

{
if (WebSocket.State is WebSocketState.Open)
{
await WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it reasonable to use CancellationToken.None here? Since we're disposing the websocket if the remote party fails to respond to the Close request and we don't have a keep alive set, we will basically hang here.

Would it not be better if we have some timeout for the close to complete?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. The close timeout is one of the open questions at the moment. The full list is in #111217 (comment) -- we'd appreciate your thoughts on it as well 🙏

Copy link
Contributor

@zlatanov zlatanov Apr 30, 2025

Choose a reason for hiding this comment

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

From an API standpoint I would prefer if the close timeout can be specified in WebSocketCreationOptions much like the KeepAliveTimeout. Doing so eliminates the need for the consumers of the WebSocket to know about it. I would even go further than this, making the CloseTimeout have a meaningful value by default.

@stephentoub
Copy link
Member Author

Closing until design concerns are addressed

@stephentoub stephentoub closed this May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add APIs to WebSocket which allow it to be read as a Stream
3 participants