Skip to content

Coalesce concurrent download requests for the same object#1929

Merged
tyrielv merged 1 commit intomicrosoft:masterfrom
tyrielv:tyrielv/oom-request-coalescing
Apr 1, 2026
Merged

Coalesce concurrent download requests for the same object#1929
tyrielv merged 1 commit intomicrosoft:masterfrom
tyrielv:tyrielv/oom-request-coalescing

Conversation

@tyrielv
Copy link
Copy Markdown
Contributor

@tyrielv tyrielv commented Mar 27, 2026

Problem

Under memory pressure, multiple git.exe processes request the same loose object via named pipes simultaneously. Each request triggers an independent HTTP download — the incident log showed 48,176 events with zero available connections, caused by redundant downloads of the same SHAs.

Change

Adds a ConcurrentDictionary<string, Lazy<DownloadAndSaveObjectResult>> to GVFSGitObjects so only one download runs per objectId at a time. Concurrent callers share the result. Entry is removed after completion so subsequent requests get fresh attempts.

Key review areas

  • Thread safety of Lazy + ConcurrentDictionary pattern (race between GetOrAdd and TryRemove in finally)
  • CancellationToken capture: first caller's token is used for all coalesced callers
  • Telemetry: coalesced requests are logged at Informational level

Testing

3 new unit tests: concurrent coalescing, independent SHAs not coalesced, failed download allows retry.

@tyrielv tyrielv force-pushed the tyrielv/oom-request-coalescing branch from 6947db0 to 96a4481 Compare March 27, 2026 22:49
@tyrielv tyrielv marked this pull request as ready for review March 27, 2026 23:53
@tyrielv tyrielv force-pushed the tyrielv/oom-request-coalescing branch from 96a4481 to 6d657ff Compare March 31, 2026 17:48
Adds a ConcurrentDictionary<string, Lazy<DownloadAndSaveObjectResult>> to
GVFSGitObjects so only one download runs per objectId at a time. Concurrent
callers share the result via the Lazy<T> pattern. The entry is removed after
completion using value-aware removal (ICollection<KVP>.Remove) to prevent an
ABA race where a straggling thread's finally could remove a newer Lazy
created by a later wave of requests.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv force-pushed the tyrielv/oom-request-coalescing branch from 6d657ff to 579f483 Compare March 31, 2026 20:26
@tyrielv tyrielv merged commit cddda1c into microsoft:master Apr 1, 2026
49 checks passed
@tyrielv tyrielv deleted the tyrielv/oom-request-coalescing branch April 1, 2026 00:49
@mjcheetham mjcheetham mentioned this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants