Skip to content

Require CancellationToken for client results (and fix cancel closing connection) #43249

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

Merged
merged 5 commits into from
Aug 20, 2022

Conversation

BrennanConroy
Copy link
Member

@BrennanConroy BrennanConroy commented Aug 12, 2022

Fixes #43054

For other types like StreamItem and Invocations we create StreamBindingFailureMessage and InvocationBindingFailureMessage respectively in the hub protocols when a failure occurs. We might want to do something similar here, but since it's late in RC1 I think we should opt for not adding a new public class and instead ignore the result value of completion messages in this scenario.

Additionally, this change adds a default timeout of 30 seconds to client result calls. This is done at the HubLifetimeManager layer because we aren't able to control all call sites of proxy.InvokeAsync. This is also an option that could potentially result in new API (DefaultClientResultTimeout or something). But again, late in RC1 that might be hard to swing. Users can pass in their own CancellationToken if they want to customize how long they will wait for a result, and this will override the 30 second default.

Went with requiring user to pass in a CancellationToken to suggest that they think about cancellation when using the feature.

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Aug 12, 2022
@BrennanConroy BrennanConroy requested a review from a team as a code owner August 17, 2022 17:10
@BrennanConroy
Copy link
Member Author

BrennanConroy commented Aug 17, 2022

Changed to remove the default timeout and require passing in a CancellationToken.

Edit: This would need to go through a quick API review if we agree on the approach.

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

I think it makes sense to try to force people to think about cancellation. Making them explicitly pass in CancellationToken.None/default seems like a reasonable way to do this. And we could add a default later if we really wanted to, right?

Anyway, let's update #43054 with the API proposal so more people can discuss.

@BrennanConroy BrennanConroy changed the base branch from main to release/7.0-rc1 August 17, 2022 23:02
@davidfowl
Copy link
Member

And we could add a default later if we really wanted to, right?

With the current API I don't think so.

@BrennanConroy
Copy link
Member Author

And we could add a default later if we really wanted to, right?

With the current API I don't think so.

We could add an option to set a default, but our default would need to be infinite 😄

@BrennanConroy
Copy link
Member Author

@dotnet/aspnet-admins could I get a merge please? Code check is failing due to approved unshipped file changes.

@dougbu
Copy link
Contributor

dougbu commented Aug 19, 2022

@adityamandaleeka is this approved for RC1❔

@adityamandaleeka
Copy link
Member

Approved, this prevents a potentially bad disconnect issue in new 7.0 work.

@dougbu dougbu enabled auto-merge (squash) August 19, 2022 18:50
@dougbu
Copy link
Contributor

dougbu commented Aug 19, 2022

Will complain the auto-squish didn't work and that'll hopefully remind me to merge this 😄

@BrennanConroy
Copy link
Member Author

Ok, now it's ready.

@halter73 halter73 changed the title Cancel client results after a default timeout (and fix cancel closing connection) Require CancellationToken for client results (and fix cancel closing connection) Aug 19, 2022
@adityamandaleeka
Copy link
Member

Looks like @dougbu or @wtgodbe have to merge this since it's technically red.

@dougbu dougbu merged commit bb7c4a9 into release/7.0-rc1 Aug 20, 2022
@dougbu dougbu deleted the brecon/cancelresult branch August 20, 2022 01:52
@dougbu
Copy link
Contributor

dougbu commented Aug 20, 2022

You could have done the JIT thing @adityamandaleeka but pinging me was fine, especially because my thought that auto-squish would complain when a build failed didn't pan out😀

@adityamandaleeka
Copy link
Member

That's a big hammer and I want to be sparing in my use of it 😄

@BrennanConroy BrennanConroy added this to the 7.0-rc1 milestone Aug 20, 2022
halter73 pushed a commit to halter73/AspNetCore that referenced this pull request Nov 20, 2024
…connection) (dotnet#43249)

* WIP default cancel timeout for invokes
* change
* remove default token and default timeout
* fix build
* Update src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canceled client result can result in connection being closed
6 participants