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

Error installing multiple packages in parallel using COM API #4587

Closed
AmelBawa-msft opened this issue Jun 26, 2024 · 2 comments · Fixed by #4592
Closed

Error installing multiple packages in parallel using COM API #4587

AmelBawa-msft opened this issue Jun 26, 2024 · 2 comments · Fixed by #4592
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Milestone

Comments

@AmelBawa-msft
Copy link
Contributor

Brief description of your issue

From Dev Home, when calling the COM API during installation from multiple threads running in parallel, often an exception occurs for one of the calls.

Dev Home logs

System.Runtime.InteropServices.COMException (0x8007139F)
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.Microsoft.Management.Deployment.ICatalogPackageMethods.get_DefaultInstallVersion(IObjectReference _obj)
   at Microsoft.Management.Deployment.CatalogPackage.get_DefaultInstallVersion()
   at DevHome.Services.WindowsPackageManager.Services.WinGetPackageInstaller.InstallPackageInternalAsync(CatalogPackage package, String version, Guid activityId)

AppInstaller logs

2024-06-26 10:00:53.540 [FAIL] C:\__w\1\s\external\pkg\src\AppInstallerRepositoryCore\Microsoft\SQLiteIndexSource.cpp(24)\WindowsPackageManager.dll!00007FFB8CE49D82: (caller: 00007FFB8CE7372E) Exception(2) tid(6288) 8007139F The group or resource is not in the correct state to perform the requested operation.


2024-06-26 10:00:53.541 [FAIL] WindowsPackageManager.dll!00007FFB8CF09106: ReturnHr(2) tid(6288) 8007139F The group or resource is not in the correct state to perform the requested operation.

    Msg:[C:\__w\1\s\external\pkg\src\AppInstallerRepositoryCore\Microsoft\SQLiteIndexSource.cpp(24)\WindowsPackageManager.dll!00007FFB8CE49D82: (caller: 00007FFB8CE7372E) Exception(2) tid(6288) 8007139F The group or resource is not in the correct state to perform the requested operation.

]

Steps to reproduce

From Dev Home, attempt to install:

  • Notepad++.Notepad++
  • Vim.Vim

Expected behavior

Ability to call the API from multiple threads

Actual behavior

At least one call will throw an exception (logs above)

Environment

Windows Package Manager (Preview) v1.9.1763-preview
@Trenly
Copy link
Contributor

Trenly commented Jun 26, 2024

Correct me if I'm wrong, but isn’t this a limitation of MSI installers in general, where only one operation can be performed at a time anyways? Even with exe installers, although they can run at the same time if they attempt to access the same resource, there could be issues.

To me it seems that best practice for any automated installation is to only allow a single thread to process an install at any given time

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage Issue need to be triaged label Jun 26, 2024
@JohnMcPMS
Copy link
Member

Correct me if I'm wrong, but isn’t this a limitation of MSI installers in general, where only one operation can be performed at a time anyways? Even with exe installers, although they can run at the same time if they attempt to access the same resource, there could be issues.

To me it seems that best practice for any automated installation is to only allow a single thread to process an install at any given time

We already take care of that in the COM server, doing the things that we can in parallel (downloads) and serializing the parts that we must (installs [except of MSIX, because it takes care of that]).

@AmelBawa-msft was able to capture a TTT for me and I determined that it was an issue in winget caused by a lack of thread safety around our opening of the tracking catalog (really, around the shared_ptr where we store it). So ultimately the error occurs due to a race on searching using that source/catalog the first time.

if (!m_trackingCatalog)
{
m_trackingCatalog = PackageTrackingCatalog::CreateForSource(*this);
}

@denelon denelon added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Jun 27, 2024
JohnMcPMS added a commit that referenced this issue Jun 27, 2024
…log (#4592)

Fixes #4587 

## Change
Hold the tracking catalog object in a `shared_ptr` and use the atomic
functions to ensure that only one thread can initialize it.
@denelon denelon added this to the 1.8 Client milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants