Skip to content

Add unique exit code for mount authentication failures#1985

Open
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/auth-exit-code
Open

Add unique exit code for mount authentication failures#1985
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/auth-exit-code

Conversation

@tyrielv
Copy link
Copy Markdown
Contributor

@tyrielv tyrielv commented May 22, 2026

Summary

When gvfs mount fails due to authentication, both GVFS.Mount.exe and gvfs.exe now exit with ReturnCode.AuthenticationError (9) instead of GenericError (3), enabling callers to distinguish auth failures from other errors.

Changes

  • ReturnCode.AuthenticationError = 9 — new enum value
  • GitAuthentication.TryInitializeAndQueryGVFSConfig — added out bool isAuthFailure parameter that explicitly classifies auth failures:
    • Credential fetch failure → auth failure
    • 401/403 on credentialed retry → auth failure
    • Other failures (500, timeout, network) → not auth failure
  • InProcessMount — uses isAuthFailure to select ReturnCode.AuthenticationError when calling FailMountAndExit
  • GVFSPlatform.StartBackgroundVFS4GProcess — returns Process (was void) so MountVerb can read the mount process exit code
  • MountVerb — captures the mount process handle, waits up to 1s for exit on failure, and propagates the exit code to the caller

Testing

  • All 811 unit tests pass
  • Auth failure classification tested against four scenarios:
    1. Non-401 on anonymous probe → NOT auth (correct)
    2. 401 + credential fetch fails → IS auth (correct)
    3. 401 + creds obtained + retry returns 401/403 → IS auth (correct)
    4. 401 + creds obtained + retry returns 500/timeout → NOT auth (correct)
  • Verified that Azure DevOps returns proper 401 (not 302/203 redirect) for the anonymous config probe because HttpRequestor sends the X-TFS-FedAuthRedirect: Suppress header on all requests

Future Work

Concurrent mount exit code propagation: When two gvfs mount commands run simultaneously, the second mount process (GVFS.Mount.exe) fails to acquire the mount lock and exits with MountAlreadyRunning (8). If the first mount also fails (e.g., due to auth), MountVerb for the second invocation currently reports MountAlreadyRunning rather than the first mount's actual failure reason. A follow-up PR will address this by having the mount process persist its exit status so that concurrent mount attempts can propagate the correct error.

Early exit detection: Currently, if GVFS.Mount.exe exits before starting its named pipe server (as happens with auth failures), MountVerb still waits for the full named pipe connection timeout (60s, or 300s unattended) before checking the process exit code. A follow-up PR will add early exit detection so MountVerb can fail fast when the mount process has already terminated.

When GVFS.Mount.exe fails due to authentication (credential fetch
failure or 401/403 after credentialed retry), it now exits with
ReturnCode.AuthenticationError (9) instead of GenericError (3).

The gvfs.exe mount verb captures the GVFS.Mount.exe process handle
and propagates its exit code on mount failure, so callers of
'gvfs mount' can distinguish auth failures from other errors.

Changes:
- Add ReturnCode.AuthenticationError = 9
- Add 'out bool isAuthFailure' to TryInitializeAndQueryGVFSConfig
  to explicitly classify auth failures (credential fetch failure
  or 401/403 on credentialed retry)
- InProcessMount uses isAuthFailure to select the exit code
- StartBackgroundVFS4GProcess returns Process so MountVerb can
  read the mount process exit code after failure

Resolves AB#61375690

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv marked this pull request as ready for review May 26, 2026 17:41
@tyrielv tyrielv enabled auto-merge May 26, 2026 17:48
@tyrielv tyrielv requested a review from KeithIsSleeping May 26, 2026 18:43
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.

1 participant