Skip to content

Packaged preindexed source read opens are serialized behind an exclusive mutex under concurrent winget usage #6167

Description

Brief description of your issue

Packaged winget appears to serialize read-only opens of the preindexed winget source behind a single exclusive cross-process mutex. Under concurrent winget usage, commands that should be quick source reads can stall for tens of seconds or longer before doing meaningful work.

Steps to reproduce

Run several concurrent show commands and print elapsed time for each job:

$w = (Get-Command winget.exe).Source

1..6 | ForEach-Object {
    $i = $_
    Start-Job -ArgumentList $i, $w {
        param($i, $w)
        $s = [Diagnostics.Stopwatch]::StartNew()
        & $w show --id Devolutions.RemoteDesktopManager --exact --source winget --disable-interactivity --accept-source-agreements *> $null
        [pscustomobject]@{
            Job      = $i
            Seconds  = [math]::Round($s.Elapsed.TotalSeconds, 3)
            ExitCode = $LASTEXITCODE
        }
    }
} | Wait-Job | Receive-Job | Sort-Object Job | Format-Table -AutoSize

Sample run

Job Seconds ExitCode
--- ------- --------
  1   44.84        0
  2  163.93        0
  3  122.67        0
  4  204.52        0
  5   86.86        0
  6  241.91        0

All six commands succeeded, but some waited several minutes.

Expected behavior

Read-only commands such as winget show and winget search should not block behind unrelated concurrent winget activity when they only need to open and read the packaged source index.

Actual behavior

The command often appears idle for a long time, then completes quickly once source open proceeds.

Analysis

The relevant path appears to be in:

  • src\AppInstallerRepositoryCore\Microsoft\PreIndexedPackageSourceFactory.cpp
  • src\AppInstallerCommonCore\Synchronization.cpp
  • src\AppInstallerRepositoryCore\RepositorySource.cpp

Observed behavior suggests that read-only packaged source open uses the same named cross-process mutex as source update/add/remove operations:

PreIndexedSourceCPL_Microsoft.Winget.Source_8wekyb3d8bbwe

In instrumented runs, the expensive part was the wait to acquire that mutex, not the actual source read work. Representative timings from local investigation:

  • SQLite search: ~3-5 ms
  • warm package version data load: ~6-10 ms
  • warm manifest load: ~12-18 ms
  • packaged source open once it proceeds: ~80-130 ms
  • mutex wait in contended runs: ~10 s, ~26 s, and higher in multi-process runs

This creates a convoy effect:

  1. one process acquires the preindexed source mutex
  2. other processes queue behind it, including read-only commands
  3. the waiting time dominates wall-clock duration even though their own source read work is small

One detail that stood out while reading the code is that comments refer to a reader-writer lock, while the current implementation appears to use a plain exclusive mutex.

Impact

This likely affects more than winget show. Any command that opens the packaged winget source may be impacted, including:

  • winget search
  • winget show
  • winget install during package lookup / manifest resolution
  • winget upgrade during lookup / manifest resolution
  • winget download

For scripts or tools that invoke winget concurrently like UniGetUI, or just when developing winget locally with multiple AI agents running winget commands concurrently, this can cause highly variable latency and very large slowdowns in otherwise read-mostly workflows.

Activity

  1. added
    Issue-Feature
    and removed
    Needs-Triage
    on Apr 22, 2026
  2. added
    Area-Performance
    on Apr 22, 2026
  3. JohnMcPMS commented on Apr 23, 2026

    @JohnMcPMS
    Member

    Here are my local results with current winget (v1.29.140-preview):

    Job Seconds ExitCode RunspaceId
    --- ------- -------- ----------
      1    0.61        0 e4692f7c-0e94-42fd-b4af-e024b597f77f
      2    0.62        0 6f9c289e-21cf-4a13-9368-97bb56896fc0
      3    0.61        0 3c0186cc-a045-4402-9705-c9c85477c17a
      4    0.61        0 0eace932-c125-43d3-a11b-9e175c390748
      5    0.60        0 9f6a1746-05ac-443f-8d92-fc4e6273f19d
      6    0.59        0 29193bce-6fd6-4124-84dd-5ba91a82c3d3
    

    I don't see how the changes in your PR (for this issue alone) could possibly lead to the kind of speed increases that you show in your patched version. In fact, your patched numbers are very similar to my unpatched ones.

    Did your reported patched results include both changes? Is it the ACL change that is really causing the speedup? The lock is held during a call to GetPathTo(Temp) (via FileCache). With only this issue's change, I would expect that all of them would complete closer to the same (quite long) 45 seconds. That is assuming that NTFS doesn't just serialize us on the SetNamedSecurityInfoW call anyway.

    I'm not really opposed to your locking change, although I think it could be cleaned up a bit for readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PerformanceIssue-Feature

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions