Skip to content

fix: improve auth mutex error handling to prevent crashes - #3339

Closed
ChrisWiles wants to merge 2 commits into
openai:mainfrom
ChrisWiles:fix/auth-mutex-error-handling
Closed

ChrisWiles wants to merge 2 commits into
openai:mainfrom
ChrisWiles:fix/auth-mutex-error-handling

Conversation

@ChrisWiles

@ChrisWiles ChrisWiles commented Sep 9, 2025 •

Copy link
Copy Markdown

Summary

Fixes mutex error handling in auth functions that could crash the application.

The Problem

Three auth functions used .unwrap() on mutex locks, which crashes the program if the mutex is poisoned (happens when a thread panics while holding the mutex):

self.auth_dot_json.lock().unwrap() // CRASH if mutex poisoned

Since these handle authentication tokens, crashes could happen during normal auth operations.

The Fix

  • Functions returning Result now return errors instead of crashing
  • Functions returning Option return None and log errors gracefully
  • Added bounds checking to prevent inconsistent auth state

Tests

Added test to verify normal mutex behavior still works correctly.

ChrisWiles and others added 2 commits September 8, 2025 19:28
Fixed three critical issues in auth.rs where mutex lock failures were
handled incorrectly:

1. refresh_token() silently ignored lock failures, causing inconsistent
   state between file and in-memory cache
2. get_token_data() used unwrap() on mutex lock, causing panics
3. get_current_auth_json() used unwrap() on mutex lock, causing panics

These functions handle authentication tokens, so failures could crash
the application or leave users in inconsistent auth states.

Changes:
- Functions returning Result now return errors on lock failure
- Functions returning Option return None and log errors gracefully
- Added test to verify normal mutex behavior still works
@etraut-openai

Copy link
Copy Markdown
Contributor

Thanks for the contribution, and apologies for the slow response. We've received a lot of PRs, and we've fallen behind in reviewing them.

Is there a bug report associated with this PR? We generally want to have a bug report associated with each PR. This helps us track, prioritize, and do risk assessment.

Does this PR fix a behavioral problem that you or other users are seeing, or is it purely a code robustness improvement?

The underlying code has changed a bit since you posted the PR. Could you resolve the merge conflicts?

@etraut-openai etraut-openai added the needs-response Additional information is requested label Nov 4, 2025
@bolinfest

Copy link
Copy Markdown
Collaborator

@ChrisWiles have you seen this happen in the wild? If this is happening in the wild, then it implies a bug in our business logic. This change would potentially sweep that issue under the rug.

@bolinfest

Copy link
Copy Markdown
Collaborator

This does not appear to be an appropriate fix: closing.

@bolinfest bolinfest closed this Nov 7, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2025
@openai openai unlocked this conversation Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-response Additional information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants