Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

[feature/dotnet8] Fix race in KernelScheduler - #3222

Merged
jonsequitur merged 4 commits into
dotnet:feature/dotnet8from
shyamnamboodiripad:race
Oct 5, 2023
Merged

jonsequitur merged 4 commits into
dotnet:feature/dotnet8from
shyamnamboodiripad:race

Conversation

@shyamnamboodiripad

Copy link
Copy Markdown
Contributor

KernelScheduler._currentlyRunningOperation and / or KernelScheduler._currentlyRunningTopLevelOperation (both of which impact the value returned from KernelScheduler.CurrentValue) can sometimes point to the command that scheduler was running (instead of having value null) even after the operation.TaskCompletionSource.Task is complete.

This PR updates the scheduler to always ensure that KernelScheduler._currentlyRunningOperation (and
KernelScheduler._currentlyRunningTopLevelOperation if applicable) are always reset to null right before operation.TaskCompletionSource.Task is completed. This in turn ensures that KernelScheduler.CurrentValue will always have the value null after the task returned from Kernel.RunAsync() (i.e. operation.TaskCompletionSource.Task) has been awaited.

NOTE: I will port the same fix to main once I have validated that the race no longer exists in CI in the feature/dotnet8 branch (where the race was first encountered).

@jonsequitur
jonsequitur merged commit eff4b7a into dotnet:feature/dotnet8 Oct 5, 2023
@shyamnamboodiripad
shyamnamboodiripad deleted the race branch October 5, 2023 22:01
shyamnamboodiripad added a commit to shyamnamboodiripad/interactive that referenced this pull request Oct 5, 2023
* Use KernelCommandResult.Events in place of Kernel.Events.

* Fix race.

* Enable more complete logging for commands and events in tests.

* Add a test.
shyamnamboodiripad added a commit that referenced this pull request Oct 9, 2023
…evelOperation (#3235)

`_currentlyRunningTopLevelOperation` was not being reset in the case where a top-level operation would schedule child operations. In this case, `_currentlyRunningOperation` was correctly being reset when each child operation was completed. However, when the parent operation was completed, we would fail to reset `_currentlyRunningTopLevelOperation` since we were comparing `_currentlyRunningTopLevelOperation` with the value of `_currentlyRunningOperation` (and `_currentlyRunningOperation` would have a value null at this point because it was reset to null when the child operation was completed above).

The above bug was breaking parenting (and command token assignment) for subsequent commands. Subsequent commands were being incorrectly parented to the stale value reflected in `_currentlyRunningTopLevelOperation`. And this in turn was leading to hangs.

This was an unfortunate regression triggered by the changes in #3222 that fixed a race condition. The regression happened because were missing tests that exercised the above scenario. I have included some tests for this as part of the current commit.

Also add a skipped test for related issue #3236.
shyamnamboodiripad added a commit to shyamnamboodiripad/interactive that referenced this pull request Oct 9, 2023
…evelOperation (dotnet#3235)

`_currentlyRunningTopLevelOperation` was not being reset in the case where a top-level operation would schedule child operations. In this case, `_currentlyRunningOperation` was correctly being reset when each child operation was completed. However, when the parent operation was completed, we would fail to reset `_currentlyRunningTopLevelOperation` since we were comparing `_currentlyRunningTopLevelOperation` with the value of `_currentlyRunningOperation` (and `_currentlyRunningOperation` would have a value null at this point because it was reset to null when the child operation was completed above).

The above bug was breaking parenting (and command token assignment) for subsequent commands. Subsequent commands were being incorrectly parented to the stale value reflected in `_currentlyRunningTopLevelOperation`. And this in turn was leading to hangs.

This was an unfortunate regression triggered by the changes in dotnet#3222 that fixed a race condition. The regression happened because were missing tests that exercised the above scenario. I have included some tests for this as part of the current commit.

Also add a skipped test for related issue dotnet#3236.
shyamnamboodiripad added a commit that referenced this pull request Oct 9, 2023
…rrentlyRunningTopLevelOperation (#3237)

Cherry-picked from #3235.

`_currentlyRunningTopLevelOperation` was not being reset in the case where a top-level operation would schedule child operations. In this case, `_currentlyRunningOperation` was correctly being reset when each child operation was completed. However, when the parent operation was completed, we would fail to reset `_currentlyRunningTopLevelOperation` since we were comparing `_currentlyRunningTopLevelOperation` with the value of `_currentlyRunningOperation` (and `_currentlyRunningOperation` would have a value null at this point because it was reset to null when the child operation was completed above).

The above bug was breaking parenting (and command token assignment) for subsequent commands. Subsequent commands were being incorrectly parented to the stale value reflected in `_currentlyRunningTopLevelOperation`. And this in turn was leading to hangs.

This was an unfortunate regression triggered by the changes in #3222 that fixed a race condition. The regression happened because were missing tests that exercised the above scenario. I have included some tests for this as part of the current commit.

Also add a skipped test for related issue #3236.
colombod added a commit that referenced this pull request Nov 22, 2023
* update dependencies from arcade

* update to dotnet 8

* skip csharpproject kernel tests due to different binlog format

* skip docker build step

* set tool feed to experimental

* update arcade sdk (#2697)

* upgrade projects to <TargetFramework>net8.0</TargetFramework>

* fix api contract

* try multi taget

* Update arcade

* remove multi targets

* Fix new warnings reported from .NET8 SDK.

* new projcts

* [feature/dotnet8] Fix race in KernelScheduler (#3222)

* Use KernelCommandResult.Events in place of Kernel.Events.

* Fix race.

* Enable more complete logging for commands and events in tests.

* Add a test.

* [feature/dotnet8] Fix bug related to resetting of KernelScheduler._currentlyRunningTopLevelOperation (#3237)

Cherry-picked from #3235.

`_currentlyRunningTopLevelOperation` was not being reset in the case where a top-level operation would schedule child operations. In this case, `_currentlyRunningOperation` was correctly being reset when each child operation was completed. However, when the parent operation was completed, we would fail to reset `_currentlyRunningTopLevelOperation` since we were comparing `_currentlyRunningTopLevelOperation` with the value of `_currentlyRunningOperation` (and `_currentlyRunningOperation` would have a value null at this point because it was reset to null when the child operation was completed above).

The above bug was breaking parenting (and command token assignment) for subsequent commands. Subsequent commands were being incorrectly parented to the stale value reflected in `_currentlyRunningTopLevelOperation`. And this in turn was leading to hangs.

This was an unfortunate regression triggered by the changes in #3222 that fixed a race condition. The regression happened because were missing tests that exercised the above scenario. I have included some tests for this as part of the current commit.

Also add a skipped test for related issue #3236.

* update_sdk (#3320)

* fix

* Suppress new warning reported from .NET8 SDK.

* these files are no longer needed

* address comment

* revert change

---------

Co-authored-by: Brett V. Forsgren <brettfo@microsoft.com>
Co-authored-by: Shyam Namboodiripad <gnamboo@microsoft.com>
Co-authored-by: Shyam N <shyamnamboodiripad@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants