Skip to content

Mount: prevent process crash on unhandled request handler exceptions - #2021

Merged
Tyrie Vella (tyrielv) merged 2 commits into
microsoft:masterfrom
tyrielv:tyrielv/fix-flaky-rebase-pipe
Jun 15, 2026
Merged

Tyrie Vella (tyrielv) merged 2 commits into
microsoft:masterfrom
tyrielv:tyrielv/fix-flaky-rebase-pipe

Conversation

@tyrielv

@tyrielv Tyrie Vella (tyrielv) commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Flaky functional tests like RebaseConflictWithFileReads fail with:

Read response from pipe failed (109)
error: external process '...read-object.exe' failed
fatal: unable to read beff26901f650e3e91d0d116bdc0123b7f4516b7
The repo does not appear to be mounted.

Error 109 = ERROR_BROKEN_PIPE — the mount process closed the pipe while the read-object hook was waiting for a response.

Root Cause

NamedPipeServer.OnNewConnection calls Environment.Exit on any unhandled exception from a request handler. A single transient error (network timeout, disk I/O failure, etc.) in HandleDownloadObjectRequest propagates through the call chain:

HandleDownloadObjectRequest → HandleRequest → HandleConnection → OnNewConnection → LogErrorAndExit → Environment.Exit

This crashes the entire mount process, breaking all pipe connections and causing subsequent hooks to report 'does not appear to be mounted'.

Fix

  1. HandleRequest safety net — wraps the request dispatch in a try-catch so no individual handler can crash the mount. Logs the exception and lets the connection close gracefully.

  2. HandleDownloadObjectRequest isolation — download logic extracted to DownloadObject and wrapped in ry-catch. On exception, sends a DownloadFailed response to the hook instead of killing the pipe. The read-object hook then reports a proper failure to git, which handles it more gracefully than a broken pipe.

@tyrielv
Tyrie Vella (tyrielv) force-pushed the tyrielv/fix-flaky-rebase-pipe branch from 0208851 to 551a61d Compare June 12, 2026 18:02
@tyrielv
Tyrie Vella (tyrielv) marked this pull request as ready for review June 12, 2026 18:56
@tyrielv
Tyrie Vella (tyrielv) force-pushed the tyrielv/fix-flaky-rebase-pipe branch from 5802274 to d7bc220 Compare June 12, 2026 22:16
@tyrielv
Tyrie Vella (tyrielv) force-pushed the tyrielv/fix-flaky-rebase-pipe branch 2 times, most recently from d4f389a to 729a452 Compare June 15, 2026 20:10
auto-merge was automatically disabled June 15, 2026 20:10

Pull request was closed

HandleRequest now catches exceptions from individual pipe request
handlers instead of letting them propagate to OnNewConnection, which
calls Environment.Exit on any unhandled exception. A single transient
error (network timeout, disk I/O failure) in a download handler would
crash the entire mount process, breaking all pipe connections.

Both catch sites use exception filters to exclude OutOfMemoryException,
which indicates a corrupted heap state where continuing is unsafe.
StackOverflowException and AccessViolationException are already
uncatchable in .NET Core and need no explicit exclusion.

HandleDownloadObjectRequest is refactored to isolate the download
logic in DownloadObject and wrap it in a try-catch that returns a
DownloadFailed response on exception. The read-object hook then
receives a proper failure response instead of ERROR_BROKEN_PIPE (109),
and git handles the object-not-available error more gracefully.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <[email protected]>
When GitRepoTests uses a shared enlistment (enlistmentPerTest=false),
check IsMounted() in SetupForTest before running git commands. If the
mount process crashed during a previous test, all remaining tests in
the fixture would fail with the same unhelpful 'does not appear to be
mounted' error from the pre-command hook. The early check produces a
clear message pointing to the earlier root-cause failure.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <[email protected]>
@tyrielv
Tyrie Vella (tyrielv) merged commit c379b4e into microsoft:master Jun 15, 2026
51 checks passed
Tyrie Vella (tyrielv) added a commit to tyrielv/VFSForGit that referenced this pull request Jul 9, 2026
Change the outer try-catch in HandleRequest from swallowing exceptions
to catch-log-rethrow. The original catch (PR microsoft#2021) suppressed all
exceptions except OutOfMemoryException, which could mask corruption in
state-mutating handlers like PostIndexChanged, DehydrateFolders, and
ReleaseLock — leaving the mount serving in an inconsistent state.

The catch now logs the message header and exception (context that
OnNewConnection's generic catch in NamedPipeServer does not capture),
then rethrows so fail-fast via Environment.Exit still occurs for
unhandled errors in state-mutating handlers.

The inner try-catch in HandleDownloadObjectRequest remains unchanged —
it correctly catches and returns DownloadFailed for transient
network/disk errors in the download path, which is safe because no
critical mount state is mutated.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <[email protected]>
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