Reuse a single Redis connection in records_lib::mappack::calc_scores#129
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix Redis pool starvation and deadlock issue
Harden Redis pool behavior and remove per-request double checkout deadlock path
May 26, 2026
Copilot stopped work on behalf of
ahmadbky due to an error
May 26, 2026 21:19
ahmadbky
reviewed
May 26, 2026
Copilot
AI
changed the title
Harden Redis pool behavior and remove per-request double checkout deadlock path
Reuse a single Redis connection in May 27, 2026
records_lib::mappack::calc_scores
ahmadbky
approved these changes
May 27, 2026
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.
After the deadpool 0.12.3 upgrade reduced default pool capacity, concurrent handlers that check out Redis twice in one request could starve the pool and block unrelated Redis-backed endpoints. This PR makes pool behavior explicit and removes the deadlock-prone checkout pattern in the affected handler.
Redis pool config is now explicit and stable
Set fixed Redis pool size to 16 (instead of relying on upstream defaults).
Added a pool wait timeout of 2s for connection checkout to fail fast under saturation instead of waiting indefinitely.
Removed double-checkout pattern in player_finished
Refactored the handler to reuse the already-checked-out Redis connection for the pipeline/rank update path.
Eliminates the “hold one connection, wait for another” deadlock scenario under concurrent load.
Focused guardrail test
Added a unit test around pool config construction to assert:
max_size == 16
wait timeout == 2s
Moreover,
calc_scoreswas checking out Redis twice in one function scope, and the second binding shadowed the first, keeping two pooled connections alive concurrently. This change keeps a single connection for the full function path.Problem
calc_scoresacquired one Redis connection for mappack membership/expiry handling, then acquired another for rank lookups in the map loop.Change
redis_pool.get().await?incalc_scores.redis_connfor subsequentranks::get_rank(...)calls.Effect