Skip to content

if an index error occurs while fetching a node, return master node #2575

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

Closed
wants to merge 1 commit into from

Conversation

zakaf
Copy link
Contributor

@zakaf zakaf commented Feb 6, 2023

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Please provide a description of the change here.

When an AWS Elasticache shard is added to an existing cluster, below exception occurs in redis-py.

Traceback (most recent call last):
  ...
  File "/usr/lib/python3.8-pyston2.3/site-packages/redis/cluster.py", line 876, in _determine_nodes
    node = self.nodes_manager.get_node_from_slot(
  File "/usr/lib/python3.8-pyston2.3/site-packages/redis/cluster.py", line 1382, in get_node_from_slot
    return self.slots_cache[slot][node_idx]
IndexError: list index out of range

The above exception seems to occur, when slots_cache changes dynamically, while get_node_from_slot is being executed.
In order to avoid the above exception, return the primary node, when an IndexError occurs

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2023

Codecov Report

Base: 92.28% // Head: 92.25% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (01c3251) compared to base (428d609).
Patch coverage: 50.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2575      +/-   ##
==========================================
- Coverage   92.28%   92.25%   -0.04%     
==========================================
  Files         115      115              
  Lines       29660    29663       +3     
==========================================
- Hits        27373    27365       -8     
- Misses       2287     2298      +11     
Impacted Files Coverage Δ
redis/cluster.py 90.22% <50.00%> (-0.21%) ⬇️
tests/test_asyncio/test_search.py 98.29% <0.00%> (-0.35%) ⬇️
redis/asyncio/cluster.py 91.68% <0.00%> (-0.33%) ⬇️
tests/test_asyncio/test_pubsub.py 99.37% <0.00%> (-0.16%) ⬇️
tests/test_asyncio/test_cluster.py 97.48% <0.00%> (-0.13%) ⬇️
tests/test_cluster.py 96.75% <0.00%> (-0.11%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@zakaf
Copy link
Contributor Author

zakaf commented Feb 19, 2023

@dvora-h @chayim if you guys have spare time, could you take a look at this PR?

Copy link
Contributor

This pull request is marked stale. It will be closed in 30 days if it is not updated.

@gordo-veda
Copy link

gordo-veda commented May 17, 2024

This is still a problem... the code around here should be hardened such that we throw a proper error to handle resharding, or in this case, trying another node seems harmless (since the node will point you elsewhere if it doesn't have your slot).

Is it safe to assume the zeroth node is the primary? (maybe not) but finding any working node that can point you to the right slot is i likely good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants