Skip to content

MOD-15749 Short-form CLUSTERSET: reject on non-cluster (standalone) shard (RED-207632) - #102

Closed
gabsow wants to merge 1 commit into
RedisGears:masterfrom
gabsow:tom.gabsow/RED-207632-shortform-standalone-guard
Closed

MOD-15749 Short-form CLUSTERSET: reject on non-cluster (standalone) shard (RED-207632)#102
gabsow wants to merge 1 commit into
RedisGears:masterfrom
gabsow:tom.gabsow/RED-207632-shortform-standalone-guard

Conversation

@gabsow

@gabsow gabsow commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a NULL-pointer SIGSEGV in the LibMR event-loop thread (timeseries-el) when a short-form CLUSTERSET reaches a non-cluster (standalone) shard — crash reported in RED-207632 (test_asm_happyflow_flag_toggle, ASM nightly).

Root cause

SetClusterDataShortForm builds the topology entirely from the cluster API. It calls InitClusterDataSetMyId, which does:

const char* myId = RedisModule_GetMyClusterID();   // NULL when cluster mode is off
...
memcpy(cluster->myId + zerosPadding, myId, myIdLen); // memcpy(dst, NULL, 40) -> SIGSEGV

On a standalone shard RedisModule_GetMyClusterID() returns NULL, so this is memcpy(dst, NULL, REDISMODULE_NODE_ID_LEN). It runs in the event-loop thread because MR_ClusterSet schedules MR_ClusterSetFromCommand via MR_EventLoopAddTask. This matches the crash exactly (faulting thread timeseries-el, RSI=0, RDX=0x28 = 40 = REDISMODULE_NODE_ID_LEN).

The long form is unaffected — it takes myId from the command arguments (argv[CLUSTERSET_MYID_LONG_FORM_INDEX]), never from GetMyClusterID().

Fix

Guard the short-form path with the same REDISMODULE_CTX_FLAGS_CLUSTER check MR_RefreshClusterData already uses: if the shard is not in cluster mode, log a warning and return REDISMODULE_ERR (the same failure contract as the sibling "slot-ranges API missing" rejection right above it) instead of crashing. The shard stays unconfigured until cluster mode is enabled or a long-form CLUSTERSET / REFRESHCLUSTER arrives.

Verification

  • make -C src/ compiles cleanly with the change.
  • Path analysis confirms only the short-form + standalone case is affected; long-form and clustered short-form paths are unchanged.

Note

Low Risk
Small defensive guard on an error path already used elsewhere; long-form and clustered short-form behavior unchanged.

Overview
Fixes a SIGSEGV in the LibMR event-loop thread when short-form CLUSTERSET is handled on a standalone (non-cluster) Redis instance.

Short-form topology setup calls SetMyId, which uses RedisModule_GetMyClusterID(); that API returns NULL without cluster mode, leading to a NULL memcpy and crash. SetClusterDataShortForm now checks REDISMODULE_CTX_FLAGS_CLUSTER (same pattern as MR_RefreshClusterData): if cluster mode is off, it logs a warning and returns REDISMODULE_ERR, leaving the shard unconfigured until cluster mode is on or a long-form CLUSTERSET / REFRESHCLUSTER succeeds.

Long-form CLUSTERSET and short-form on clustered shards are unchanged.

Reviewed by Cursor Bugbot for commit 3020b2e. Bugbot is set up for automated code reviews on this repo. Configure here.

…hard (RED-207632)

SetClusterDataShortForm builds the topology from the cluster API. On a
standalone shard RedisModule_GetMyClusterID() returns NULL, and SetMyId
then runs memcpy(myId, NULL, REDISMODULE_NODE_ID_LEN) -> SIGSEGV in the
LibMR event-loop thread (crash seen in test_asm_happyflow_flag_toggle,
RED-207632). The long form is unaffected because it takes myId from the
command arguments.

Guard the short-form path with the same REDISMODULE_CTX_FLAGS_CLUSTER
check MR_RefreshClusterData already uses: on a non-cluster shard, log
and return REDISMODULE_ERR instead of crashing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gabsow

gabsow commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #103, which combines this with the sibling short-form CLUSTERSET fail-safe into a single PR (one review + one pin bump). Closing in favour of #103.

@gabsow gabsow closed this Jul 5, 2026
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.

1 participant