Skip to content

[BUG] Make auth requests in async context async. #3477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 14, 2025
Merged

Conversation

rescrv
Copy link
Contributor

@rescrv rescrv commented Jan 13, 2025

The auth methods were both sync, which led to latency on the async
thread pool. Fix that.

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@rescrv rescrv requested a review from codetheweb January 13, 2025 21:28
@rescrv rescrv force-pushed the rescrv/async-auth branch 2 times, most recently from f0f6a06 to add24a8 Compare January 13, 2025 23:19
The auth methods were both sync, which led to latency on the async
thread pool.  Fix that.
@rescrv rescrv force-pushed the rescrv/async-auth branch from add24a8 to eb39b0d Compare January 13, 2025 23:20
@rescrv rescrv changed the base branch from rescrv/async-rate-limit to main January 13, 2025 23:21
@tazarov
Copy link
Contributor

tazarov commented Jan 14, 2025

For posteriority sake. The real issue is not in the thread-pool but rather with the fact that asyc FastAPI executes on the main thread so any synchronous calls inside any of the API funcs will cause the main thread to block processing while the sync call returns, which is the reason we have run_sync calls for most API calls.

That said it might be simpler to just follow the same pattern for the funcs that don't use run_sync with an inner function to wrap the sync auth + api call.

@rescrv
Copy link
Contributor Author

rescrv commented Jan 14, 2025

@tazarov Thank you. A thread of one, that's separate from the other threads is, also, a pool, so I was sloppy in my message.

@rescrv rescrv merged commit 1828a9c into main Jan 14, 2025
78 checks passed
@rescrv rescrv deleted the rescrv/async-auth branch January 14, 2025 16:47
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.

3 participants