Repository navigation
Fix RDG check for endpoint uniqueness - #67591
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an RDG (Request Delegate Generator) endpoint de-duplication bug where endpoints sharing the same delegate signature could incorrectly collapse into a single generated interceptor, causing binding metadata differences (e.g., [FromBody(EmptyBodyBehavior = Allow)]) to be silently lost.
Changes:
- Adds a regression test to ensure two endpoints with the same delegate signature but different
[FromBody]binding behavior do not collapse. - Removes
EndpointParameter.SignatureEqualsand switches endpoint signature comparison to useEndpointParameter.Equals. - Updates signature hashing to incorporate
EndpointParameterhashing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.JsonBody.cs | Adds regression test covering shared delegate signature + differing EmptyBodyBehavior. |
| src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/StaticRouteHandlerModel/EndpointParameter.cs | Removes SignatureEquals so signature grouping relies on Equals. |
| src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator/StaticRouteHandlerModel/Endpoint.cs | Uses EndpointParameter.Equals for signature equality and updates signature hash computation. |
dffba3d to
d672abd
Compare
| SymbolEqualityComparer.IncludeNullability.Equals(other.Type, Type) && | ||
| other.KeyedServiceKey == KeyedServiceKey; | ||
|
|
||
| public bool SignatureEquals(object obj) => |
There was a problem hiding this comment.
i wonder why there was such method. And I am afraid of the implications of changing GetHashCode() - can we check where it is used? maybe EndpointParameter is a key in some dict?
Should we instead add check here?
There was a problem hiding this comment.
I think it might have been trying to optimize to re-use the methods as much as possible, but it was wrong optimization?
Fixes #66912
Before the fix, we considered the signature for both of the following endpoints as the same:
And so they collapsed into a single interceptor, even though they would otherwise have had different implementations.
This PR makes the equality of endpoint parameter stronger so that the parameter source and optionality are taken into account.
This removes SignatureEquals from EndpointParameter, which was a subset of EndpointParameter.Equals. And we now use EndpointParameter.Equals for correct and accurate equality.
In addition, Endpoint hash code calculation now considers the full hash code of the endpoint parameters, instead of taking only the type into account.