openai/codex · error

timed out after waiting for OAuth refresh lock

Error message

timed out after {acquire_timeout:?} waiting for OAuth refresh lock {}

What it means

Fired by acquire_in in the MCP OAuth refresh lock: the inter-process file lock (flock) held by another codex process refreshing the same server's credentials was not released within acquire_timeout, so this process gave up rather than proceeding with possibly stale credentials.

Solutions

  1. Retry the operation after the competing refresh completes
  2. Check for a stuck codex process holding the lock file and terminate it
  3. Remove the stale lock file under CODEX_HOME if no other process is running
  4. Increase the acquire timeout if refreshes routinely take longer
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at codex-rs/rmcp-client/src/oauth/refresh_lock.rs:91 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/ba5d236d61cb82b9. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rmcp-client/src/oauth/refresh_lock.rs:91

                    Ok(()) => return Ok(()),
                    Err(std::fs::TryLockError::WouldBlock) => {
                        if !reported_contention {
                            tracing::debug!(
                                target: LOCK_CONTENTION_EVENT_TARGET,
                                lock_path = %path.display(),
                                "waiting for another process to finish refreshing MCP OAuth credentials"
                            );
                            reported_contention = true;
                        }
                        sleep(REFRESH_LOCK_RETRY_SLEEP).await;
                    }
                    Err(error) => return Err(std::io::Error::from(error)),
                }
            }
        })
        .await
        .map_err(|_| {
            anyhow!(
                "timed out after {acquire_timeout:?} waiting for OAuth refresh lock {}",
                path.display()
            )
        })?
        .with_context(|| format!("failed to lock OAuth refresh lock {}", path.display()))?;

        Ok(Self { _file: file })
    }
}

#[cfg(test)]
#[path = "refresh_lock_tests.rs"]
mod tests;

View on GitHub (pinned to 339751715c)