fix: prevent monitor crash when CLUSTER SLOTS times out#46
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens eredis_cluster_monitor against eredis:q(Connection, ["CLUSTER","SLOTS"]) exiting (e.g., timeout) during slot refresh, preventing the monitor gen_server from crashing and adding a regression test for the behavior.
Changes:
- Wrap
CLUSTER SLOTSquery insafe_get_cluster_slots/1to convertexitinto an error tuple. - Introduce
safe_eredis_stop/1and use it on some slot-fetch paths to reduce crash risk during cleanup. - Add an EUnit regression test covering the timeout/exit case during
refresh_mapping/2.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/eredis_cluster_monitor.erl |
Adds safe wrapper for CLUSTER SLOTS and safe stop helper; updates slot refresh path to use them. |
test/eredis_cluster_tests.erl |
Adds regression test to ensure monitor survives CLUSTER SLOTS timeout/exit during refresh. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Background
This PR addresses a Redis Cluster refresh-timeout crash in
eredis_clustermonitor process on thebranch-0.7.xline.Problems Fixed
Monitor crash during slot refresh timeout
eredis_cluster_monitor:get_cluster_slots/3callederedis:q(Connection, ["CLUSTER", "SLOTS"])directly in agen_servercall path.eredis:q/2exits on timeout, the exception could bubble up and terminate the monitor process.Potential unsafe connection stop in fallback branches
unknown command/cluster disabled), stop used plaineredis:stop/1.safe_eredis_stop/1.Regression test cleanup instability
noproctermination reports.Typical Error Logs Covered
These are the key log patterns related to this issue:
Before this fix, timeout could additionally lead to monitor termination logs (for example
Generic server monitor_* terminatingdue to refresh path exceptions).Changes
src/eredis_cluster_monitor.erlsafe_get_cluster_slots/1to catchexitfromeredis:q/2and convert it into normal{error, ...}flow.safe_eredis_stop/1consistently in allCLUSTER SLOTSbranches.test/eredis_cluster_tests.erlsrc/eredis_cluster.appup.src0.7.9.0.7.8.Verification
/home/moo/Worksapce/emqx-enterprise/rebar3 as test eunit -g eredis_cluster_tests:monitor_reload_slots_timeout_test_ -v