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

Deadlock at ExecuteSubmission vs LoggingService during shutdown #6712

Closed
rokonec opened this issue Jul 27, 2021 · 0 comments · Fixed by #6717
Closed

Deadlock at ExecuteSubmission vs LoggingService during shutdown #6712

rokonec opened this issue Jul 27, 2021 · 0 comments · Fixed by #6717
Assignees
Labels
bug performance Performance-Scenario-Build This issue affects build performance. triaged Visual Studio Issues relevant to Visual Studio scenarios

Comments

@rokonec
Copy link
Contributor

rokonec commented Jul 27, 2021

Issue Description

This deadlock has been detected while investigating
This bug has surfaced as hang at BuildManager.EndBuild.

Steps to Reproduce

This race condition triggered deadlock is very hard to reproduce.
However there are many CABs which includes devenv process dump which helped during issue investigation.

I have used this CAB during investigation.

Analysis

During execution BuildManager.ExecuteSubmission if build is canceled at particular time and following if branch is entered

if (_shuttingDown)
{
// We were already canceled!
AddBuildRequestToSubmission(submission, resolvedConfiguration.ConfigurationId);
BuildResult result = new BuildResult(submission.BuildRequest, new BuildAbortedException());
submission.CompleteResults(result);
submission.CompleteLogging(true);
CheckSubmissionCompletenessAndRemove(submission);
return;
}

Line
submission.CompleteLogging(true);
will block inside _syncLock and wait for all messages of logging service to be processed. Processing messages of logging service is performed on thread pool and it could callback BuildManager, for example:
private void OnProjectFinished(object sender, ProjectFinishedEventArgs e)
{
lock (_syncLock)
{

Locking _syncLock in callback from LoggingService concludes this deadlock.

Prove:
image

Analysis

Code as is, is very fragile and hard to maintain. We shall strategically avoid, if possible, infinite lock-blocking callbacks from LoggingService into BuildManager
Proposed solution:

  • Code in OnProjectStarting/Finishing seems to be dead. Nothing uses its results. I recommend to delete it and stop propagating project started and finished to BuildManager.
  • OnThreadException
    • shall either somehow detect possible deadlock and throws with inner exception
    • or use lock timeout and throws with inner exception after timeout

Versions & Configurations

This error might have been there for ages, at least since 2018 commit 764fe79.

@rokonec rokonec added bug needs-triage Have yet to determine what bucket this goes in. performance Performance-Scenario-Build This issue affects build performance. Visual Studio Issues relevant to Visual Studio scenarios and removed needs-triage Have yet to determine what bucket this goes in. labels Jul 27, 2021
@rokonec rokonec self-assigned this Jul 27, 2021
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug performance Performance-Scenario-Build This issue affects build performance. triaged Visual Studio Issues relevant to Visual Studio scenarios
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants