Skip to content

Fix invalid continuation caused by exception after inlining in TryRunInline #115659

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 16 commits into from
Jun 2, 2025

Conversation

kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented May 16, 2025

Description

When a task was inlined in TryRunInline, and if an exception was thrown after inlining, it would call Finish in the catch block due to an invalid taskQueued value, which set the sentinel in the continuation object. Later, this could cause ExecuteWithThreadLocal to invoke Finish again and try to run the sentinel as a continuation, throwing InvalidCastException.

Contributes to #83520

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

Cc. @stephentoub

@stephentoub
Copy link
Member

Thanks! If this is the root cause, it's interesting that folks have only started reporting it recently. As far as I can tell, it's been like this for 15 years. :) You also mentions this "contributes" to the original issue; do you believe this is only part of it?

@kotlarmilos
Copy link
Member Author

Thanks! If this is the root cause, it's interesting that folks have only started reporting it recently. As far as I can tell, it's been like this for 15 years. :) You also mentions this "contributes" to the original issue; do you believe this is only part of it?

I believe this is the only part to the fix, though I can’t say for sure. It’s interesting that reports have only started appearing recently.

@stephentoub stephentoub marked this pull request as ready for review May 29, 2025 13:22
@kotlarmilos
Copy link
Member Author

The reproduction test is unreliable. It fails under debug configurations, and I haven’t been able to set conditions for consistently successful runs. Adding more retry attempts could improve reliability, but it would also slow down the CI.

@stephentoub Let me know how you want to proceed:

  1. Spend more time to get reliable test
  2. Merge this change and provide a private build so customers can test it against .NET 9 before backporting

@stephentoub
Copy link
Member

Whether or not it fully solves the issue, the fix is small and correct and shouldn't hurt, so let's go ahead and merge it. Thanks.

@stephentoub stephentoub merged commit 4bdcb8d into dotnet:main Jun 2, 2025
142 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants