Fix cache initialization race condition for OAuth - #197
Merged
Conversation
Problems fixed: 1. PhoenixKit.Config.UeberAuth was incorrectly accessing Ueberauth configuration through PhoenixKit.Config methods, which only look in the :phoenix_kit application environment 2. Cache module had unused warming functions from old implementation Changes: - Fixed get_all() to use Application.get_env(:ueberauth, Ueberauth, []) instead of Config.get_list(:ueberauth, []) - Fixed set_all() to use Application.put_env(:ueberauth, Ueberauth, config) instead of Config.set(:ueberauth, config) - Removed unused handle_cache_warming/4 and handle_sync_warming/3 functions from PhoenixKit.Cache This ensures UeberAuth configuration is correctly read from and written to the :ueberauth application environment where it belongs, and removes dead code from the Cache module.
Update cache warming strategy to load all settings data during synchronous initialization instead of loading critical settings first then remaining settings asynchronously. Changes: - Remove critical_warmer parameter from cache initialization - Load all data in handle_continue when sync_init is enabled - Add retry mechanism with exponential backoff for empty results - Simplify supervisor configuration to use single warmer function This prevents race conditions where critical OAuth settings are loaded first but then overwritten by async full cache loading returning empty results if repository is not yet ready. Benefits: - Single data load eliminates overwrite issues - Retry logic handles repository initialization delays - OAuth configuration loads reliably on cold starts - Maintains non-blocking supervisor initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed race condition in cache initialization that caused OAuth configuration to fail on cold starts due to Settings cache returning empty data.
Changes
Cache System
Files Modified
lib/phoenix_kit/cache/cache.ex- Updated warming strategy with retry logiclib/phoenix_kit/supervisor.ex- Simplified cache configurationProblem Solved
Issue: On cold start, cache would:
Solution: Load all data once in handle_continue with retry logic instead of critical-then-full strategy.
Benefits
Test Plan
Related Commits