Skip to content

[2.10] [MOD-15685] Fix crash when a legacy index spec is restored after a failed replication sync - #11621

Merged
redisearch-backport-pull-request[bot] merged 2 commits into
2.10from
backport-agent/pr-11619-to-2.10
Sep 30, 2026
Merged

redisearch-backport-pull-request[bot] merged 2 commits into
2.10from
backport-agent/pr-11619-to-2.10

Conversation

@redisearch-backport-pull-request

Copy link
Copy Markdown
Contributor

Backport of #11619 to 2.10.
Merge commit: b1b6903a1cc5b314fc64329f1434ff8f09710fdd

Describe the changes in the pull request

  1. Current: [MOD-15685] Fix crash when a legacy index spec is restored on a running server #10872 refuses a legacy ft_index0 RESTORE outside an RDB load, but it infers "outside a load" from the legacy-spec registry and the UPGRADE_INDEX rules being NULL. A failed load (LOADING_FAILED) leaves both allocated. So on a server that hasn't completed a load since startup, for example a replica whose first full sync failed and was then promoted, a truncated legacy payload still gets past the guard and crashes the server.
  2. Change: also refuse when no load is in progress (g_isLoading).
  3. Outcome: RESTORE of a legacy index spec now returns an error after a failed load too, instead of crashing the server.

Which additional issues this PR fixes

  1. MOD-15685
  2. Follow-up to [MOD-15685] Fix crash when a legacy index spec is restored on a running server #10872. Addresses the Codex review findings on its backports [8.4] [MOD-15685] Fix crash when a legacy index spec is restored on a running server #11615 and [8.10] [MOD-15685] Fix crash when a legacy index spec is restored on a running server #11612.

Main objects this PR modified

  1. IndexSpec_LegacyRdbLoad: the refusal now also checks loading state.
  2. test_legacy_module_types.py: new test that fails a full sync against a fake master, promotes the replica and restores a truncated legacy spec. Without the fix it crashes the server.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

🤖 Generated with Claude Code

…iled replication sync (#11619)

[MOD-15685] Refuse a legacy index spec RESTORE after a failed load

The guard added in #10872 refused a legacy ft_index0 load when the legacy-spec
registry or the UPGRADE_INDEX rules were NULL, taking that as "no load in
progress". A failed load breaks that assumption: LOADING_FAILED clears the
loading flag but frees neither global, and the rules are only ever freed by a
successful load. On a server that has not completed a load since startup - for
example a replica whose first full sync failed and was then promoted - a
RESTORE of a truncated legacy payload got past the guard and crashed on the
NULL spec name.

Key the refusal on g_isLoading as well. The new test drives exactly that
sequence against a fake master; it crashes the server without the fix.

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit b1b6903)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2bbe622f40

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/spec.c
// publishes it runs when the load ends. Outside one - a RESTORE of a legacy payload on a running
// server, say - refuse, so the caller sees a load failure, which for RESTORE is a command error.
// The globals alone are not enough: a failed load leaves both allocated.
if (!g_isLoading || legacySpecRules == NULL || legacySpecDict == NULL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Clear the loading flag after failed loads in non-MT builds

In the default non-MT build, this guard still permits the crashing path after a failed replication sync: Indexes_LoadingEvent sets g_isLoading at load start, but its LOADING_FAILED branch (including the reset) is compiled only under MT_BUILD. Consequently, a failed sync leaves g_isLoading true while the legacy globals remain allocated, so the malformed legacy RESTORE described by this change bypasses this condition and reaches the same null-name dereference. Handle LOADING_FAILED and reset the flag independently of MT_BUILD.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, confirmed. On 2.10 the LOADING_FAILED branch only exists under MT_BUILD, which is off by default, so a failed load left g_isLoading set and this check was bypassed. Fixed in 0968786: the failed-load branch now always resets g_isLoading, and only the thread-pool drain stays under MT_BUILD. Verified on a default (non-MT) 2.10 build: the new test crashes the server without this change and passes with it. The 8.x branches already handle LOADING_FAILED in every build.

from includes import *
from common import *
from RLTest import Env
from test_config import _grep_file_count

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Define the imported log-count helper

tests/pytests/test_config.py does not define _grep_file_count, so importing this test module raises ImportError during RLTest collection before either test can run. Add the helper to the imported module or define it locally instead of importing a nonexistent symbol.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0968786: 2.10's test_config.py doesn't have this helper, so it's now defined in the test file.

The LOADING_FAILED branch of Indexes_LoadingEvent was compiled only under
MT_BUILD, which is off by default. In a default build a failed load left
g_isLoading set, so the legacy-spec refusal keyed on it was bypassed and a
truncated legacy RESTORE still crashed. Only the thread-pool drain needs
MT_BUILD.

Also define the log-count helper in the test instead of importing it from
test_config, which does not have it on this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T08:14:16.678837Z 0968786 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kei-nan
kei-nan requested a review from dor-forer September 30, 2026 08:13
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.53%. Comparing base (a49c54f) to head (0968786).

Additional details and impacted files
@@            Coverage Diff             @@
##             2.10   #11621      +/-   ##
==========================================
- Coverage   89.55%   89.53%   -0.02%     
==========================================
  Files         212      212              
  Lines       36712    36712              
==========================================
- Hits        32877    32871       -6     
- Misses       3835     3841       +6     
Flag Coverage Δ
flow 84.11% <100.00%> (-0.14%) ⬇️
unit 43.00% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@redisearch-backport-pull-request
redisearch-backport-pull-request Bot added this pull request to the merge queue Sep 30, 2026
Merged via the queue into 2.10 with commit 372e308 Sep 30, 2026
16 checks passed
@redisearch-backport-pull-request
redisearch-backport-pull-request Bot deleted the backport-agent/pr-11619-to-2.10 branch September 30, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport This PR was automatically backported by an agent size:S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants