-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Support all return types from handler in filters #41310
Conversation
There was a problem hiding this 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.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits
Approved via email. @dotnet/aspnet-build Can I get help merging? |
@captainsafia do you want to address @JamesNK's comment before this goes in❔ |
Yep, it's done. |
@captainsafia You've removed the wrong line. We want to observe in that method because it's a ValueTask. |
* 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
* 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
This PR fixes an issue where users could not apply route handler filters to endpoints that returned void, void-returning
Task
s andValueTask
s, and genericValueTask
orTask
.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 aValueTask<object?>
and take in aRouteHandlerInvocationContext
. To map the return types correctly, the implementation previously indiscriminately appliedValueTask.FromResult<object?>()
to whatever the route handler returned. This meant that you could sometimes have invocations likeValueTask.FromResult(VoidReturningMethod())
orValueTask.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:Task
andValueTask
Task
andValueTask
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?
Risk
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
Packaging changes reviewed?