openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(auth): auth profile lock timeout/creation failure blocks all RPC calls (regression)

Open graycyrus opened this issue 6 months ago • 1 comments

Bug Report

Description

Auth profile file-lock acquisition fails for hundreds of users, blocking every RPC call that touches the auth profile store. This is a regression of the fix shipped in #1612 — the stale-lock recovery logic isn't covering all failure modes.

Sentry issues:

Combined impact: 1,812 events. Every RPC method that calls acquire_lock() fails — app_state_snapshot, auth reads, profile writes — leaving the app non-functional until the lock clears or the user restarts.

Error

Timed out waiting for auth profile lock
Failed to create auth profile lock
  • Platform: Windows x86_64 (10.0.26200)
  • Version: [email protected]
  • Environment: production

Root Cause Analysis

src/openhuman/credentials/profiles.rs:526-599 — acquire_lock() uses create_new(true) with a 10s busy-wait + stale-PID recovery (#1612 fix). Two failure modes remain:

  1. H1 (timeout): clear_lock_if_stale() runs once (cleared_stale flag), but if the owning process is still alive (e.g. hung RPC handler holding the lock longer than 10s), every subsequent caller times out. No deadlock detection or lock-stealing after extended hold.

  2. H8 (creation failure): retry_with_backoff retries 6 times but the error is not AlreadyExists — it's a filesystem-level failure (permissions, AV interference on Windows). The error falls through to the non-AlreadyExists branch and returns immediately with no recovery.

The 990 H1 events suggest a single long-held lock cascades into a retry storm across all concurrent RPC calls — each one independently waiting 10s, then all failing together.

Cascade

Call site Behavior File:Line
app_state_snapshot Returns error to UI → boot gate blocked profiles.rs:591
All auth-dependent RPCs Timeout after 10s → UI shows error loop profiles.rs:591
Profile writes Fail immediately on fs error profiles.rs:596

Proposed Fix

  1. Increase stale-lock recovery: re-check PID liveness periodically during the busy-wait (not just once) in case the owning process crashes mid-hold
  2. Add lock-hold timeout: if the lock file is older than e.g. 30s, force-remove regardless of PID liveness (defensive against hung holders)
  3. Windows-specific: handle AV/permission lock interference on create_new — retry with backoff on permission errors, not just AlreadyExists
  4. Add tests for concurrent lock contention and long-hold scenarios

Labels

sentry-traced-bug, os:windows, bug, priority: critical, area: core

graycyrus avatar May 18 '26 09:05 graycyrus

Image

Edit: First time user here. Can't even get in!

gothook avatar May 19 '26 18:05 gothook