Skip to content
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

Avoid UI state manipulation on background thread #68507

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Jun 9, 2023

Fixes AB#1833091

@sharwell sharwell requested a review from a team as a code owner June 9, 2023 16:36
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 9, 2023
@@ -816,7 +816,7 @@ private async Task CommitCoreAsync(IUIThreadOperationContext operationContext, b
var eventName = previewChanges ? FunctionId.Rename_CommitCoreWithPreview : FunctionId.Rename_CommitCore;
using (Logger.LogBlock(eventName, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var info = await _conflictResolutionTask.JoinAsync(cancellationToken).ConfigureAwait(false);
Copy link
Member Author

@sharwell sharwell Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This ConfigureAwait(false) was allowing the _dismissed field to be set from a background thread. Since RenameService.ActiveSession is cleared after _dismissed is set, it was allowing a UI thread check here to proceed between the point where _dismissed was set and the point where ActiveSession was cleared:

// Note: this entire sequence of steps is not cancellable. We must perform it all to get back to a correct
// state for all the editors the user is interacting with.
var cancellationToken = CancellationToken.None;
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This will now always NOP in practice, but the relocation of this switch to main thread adheres to JTF best practice. The code intentionally does not include an assertion.

@sharwell sharwell enabled auto-merge June 9, 2023 16:40
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow. good find :)

@sharwell sharwell merged commit 403f2ce into dotnet:main Jun 9, 2023
@ghost ghost added this to the Next milestone Jun 9, 2023
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants