Skip to content

Support all return types from handler in filters #41310

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 10 commits into from
Apr 26, 2022

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Apr 21, 2022

This PR fixes an issue where users could not apply route handler filters to endpoints that returned void, void-returning Tasks and ValueTasks, and generic ValueTask or Task.

Technical Detail

The current implementation of filters has logic that wraps the user provided handler into a method that complies with the RouteHandlerFilterDelegateSignature, namely it must return a ValueTask<object?> and take in a RouteHandlerInvocationContext. To map the return types correctly, the implementation previously indiscriminately applied ValueTask.FromResult<object?>() to whatever the route handler returned. This meant that you could sometimes have invocations like ValueTask.FromResult(VoidReturningMethod()) or ValueTask.FromResult(new Task("foo")).

To resolve this issue, we are improving the mapping of route handler types to ValueTask<object?> to account for three scenarios:

  • Void returning methods
  • Non-generic Task and ValueTask
  • Generic Task and ValueTask

Fixes #41213

Customer Impact

Without this fix, customers are not able to apply route handler filters to any endpoint in their application with running into exceptions or strange behavior. This bug fix allows us to achieve the stated goal of filters being applicable on all endpoints.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Change was validated manually and with automated tests. Surface area of change limited to user code that has handlers with the 3 return types outlined above.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@ghost ghost added the area-runtime label Apr 21, 2022
@captainsafia captainsafia added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels and removed area-runtime labels Apr 21, 2022
@captainsafia captainsafia marked this pull request as ready for review April 21, 2022 21:43
@captainsafia captainsafia requested a review from a team April 21, 2022 21:45
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.

Nit: I agree ExecuteAwait should be ExecuteAwaited instead for consistency with other places we do this.

@captainsafia captainsafia added the Servicing-consider Shiproom approval is required for the issue label Apr 22, 2022
@ghost
Copy link

ghost commented Apr 22, 2022

Hi @captainsafia. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

Mostly nits

@captainsafia captainsafia added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 25, 2022
@captainsafia
Copy link
Member Author

Approved via email.

@dotnet/aspnet-build Can I get help merging?

@dougbu
Copy link
Contributor

dougbu commented Apr 25, 2022

@dotnet/aspnet-build Can I get help merging?

@captainsafia do you want to address @JamesNK's comment before this goes in❔

@captainsafia
Copy link
Member Author

@captainsafia do you want to address @JamesNK's comment before this goes in❔

Yep, it's done.

@JamesNK
Copy link
Member

JamesNK commented Apr 26, 2022

@captainsafia You've removed the wrong line. We want to observe in that method because it's a ValueTask.

@dougbu dougbu merged commit 3039dc4 into dotnet:release/7.0-preview4 Apr 26, 2022
captainsafia added a commit that referenced this pull request Apr 26, 2022
* Support all return types from handler in filters
* Address feedback from peer review
* Fix up Task and ValueTask handling
* ExecuteAwait to ExecuteAwaited
* Actually await void-returning Tasks and ValueTasks
* Update comment for new logic
* Polish and update tests
* Tweaks and test fixes
* Tweak await of void-returning Task
* Fix correct ExecuteTask invocation
captainsafia added a commit that referenced this pull request Apr 26, 2022
* Support all return types from handler in filters
* Address feedback from peer review
* Fix up Task and ValueTask handling
* ExecuteAwait to ExecuteAwaited
* Actually await void-returning Tasks and ValueTasks
* Update comment for new logic
* Polish and update tests
* Tweaks and test fixes
* Tweak await of void-returning Task
* Fix correct ExecuteTask invocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants