[release/8.0-staging] Restore erroneously removed encoding of the argument count in a generic method instantiation #98825
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #98731 to release/8.0-staging
/cc @AaronRobinsonMSFT @kg
Customer Impact
Any users of the multicore jit feature would encounter silent encoding failures while recording profiles due to a defect in our encoding for generic method instances that would make them impossible to decode later. Those silent failures would then produce usually-but-not-always silent failures at runtime when performing multicore jitting of methods from the profiles.
The former failures are by their nature silent because we were forgetting to encode some important information, and no validation of the output is performed at encoding time.
The latter failures are silent because we intentionally suppress exceptions during profile playback, (presumably) in an attempt to ensure that a partially or wholly outdated profile (i.e. from an older build of the software during development, where one or more of the assemblies have changed but not all of them) will not prevent the application from starting, and the outdated profile will just not provide as much performance benefit to the user. This exception suppression was not removed as a part of the fix since doing so would imply a significant risk of application crashes for the end user.
The exception suppression is unable to suppress all the potential failures that can be triggered by this encoding error, and in the rare circumstance where the wrongly-encoded bytes were arranged just so, the application would terminate due to an assertion.
#81799 is likely caused by this issue.
Regression
The regression was caused by an erroneous removal of a write in the generic method instantiation encoder; we removed it because we misread an if-condition such that it looked like we only wrote the count when IBC was active, so it was removed along with IBC support.
PR where regression was introduced: #68717
Testing
Manual review and CI. Still looking into ways to verify it directly and will reach out to affected customers to see if they can test a build from main.
Risk
[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]
Low risk. The affected system is rarely used, and (for the exception handling reasons mentioned earlier) any potential negative impact from a defect in this change will not meaningfully worsen the experience for users over the previous state of the code. We are restoring the original intended function of this code instead of adding new code/behavior.
IMPORTANT: If this backport is for a servicing release, please verify that:
The PR target branch is
release/X.0-staging, notrelease/X.0.If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.