Skip to content

MOD-13143: Solve Hybrid ASM Memory Leak#7903

Merged
kei-nan merged 13 commits into8.4from
8.4_jk_fix_hybrid_memory_leak
Dec 29, 2025
Merged

MOD-13143: Solve Hybrid ASM Memory Leak#7903
kei-nan merged 13 commits into8.4from
8.4_jk_fix_hybrid_memory_leak

Conversation

@kei-nan
Copy link
Collaborator

@kei-nan kei-nan commented Dec 28, 2025

Describe the changes in the pull request

A clear and concise description of what the PR is solving, including:

  1. Current: There is a memory leak in 8.4 in regards to FT.HYBRID and the use of GetLocalSlots
  2. Change: Take the slots in the main thread and pass them in the concurrent ctx struct, clone them to each subquery so they will be destroyed correctly
  3. Outcome: No memory leaks from the asm feature in regard to hybrid.

Mark if applicable

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

Note

Addresses leaks and thread-safety around cluster slot ranges in query execution.

  • Change AREQ_ApplyContext to accept localSlots; store on request and pass to pipeline; update all call sites
  • Capture Slots_GetLocalSlots() on main thread in concurrent context, expose via ConcurrentCmdCtx_GetSlotsMutable, and free after worker completion
  • Add Slots_Clone and ensure slots are cloned per hybrid subquery and freed in cleanup paths (hybrid exec/debug/parse)
  • Update FT.HYBRID flow to thread slot ranges through parseHybridCommand, HybridRequest_prepareForExecution, and execution cleanup
  • Adjust tests to pass and free slot ranges
  • Command info: change FILTER arg to a block with COUNT, POLICY (ADHOC|BATCHES), optional BATCH_SIZE; bump since to 8.4.4

Written by Cursor Bugbot for commit 669f47f. This will update automatically on new commits. Configure here.

@kei-nan kei-nan requested review from GuyAv46 and JoanFM December 28, 2025 13:33
@kei-nan kei-nan self-assigned this Dec 28, 2025
@JoanFM
Copy link
Collaborator

JoanFM commented Dec 28, 2025

The implementation is ablut to change drastically, so I am not sure it is worth applying this change now and making the real ASM backport more complex

GuyAv46
GuyAv46 previously approved these changes Dec 28, 2025
@kei-nan kei-nan requested a review from oshadmi December 28, 2025 15:05
@GuyAv46
Copy link
Collaborator

GuyAv46 commented Dec 28, 2025

Should be reverted in #7829. Let's add the revert commit once this PR is merged, so we don't forget to do so.
Plus, there is the command info stuff that I guess should not be reverted. @kei-nan can you handle the revert commit?

GuyAv46
GuyAv46 previously approved these changes Dec 28, 2025
@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.06%. Comparing base (45628e4) to head (669f47f).
⚠️ Report is 3 commits behind head on 8.4.

Files with missing lines Patch % Lines
src/slot_ranges.c 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              8.4    #7903   +/-   ##
=======================================
  Coverage   86.05%   86.06%           
=======================================
  Files         332      332           
  Lines       53683    53610   -73     
  Branches    11998    11998           
=======================================
- Hits        46198    46140   -58     
+ Misses       7318     7303   -15     
  Partials      167      167           
Flag Coverage Δ
flow 84.68% <96.66%> (-0.11%) ⬇️
unit 52.39% <40.00%> (-0.03%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

GuyAv46
GuyAv46 previously approved these changes Dec 28, 2025
@kei-nan kei-nan added this pull request to the merge queue Dec 29, 2025
Merged via the queue into 8.4 with commit fa4a8bb Dec 29, 2025
32 checks passed
@kei-nan kei-nan deleted the 8.4_jk_fix_hybrid_memory_leak branch December 29, 2025 10:46
@kei-nan
Copy link
Collaborator Author

kei-nan commented Dec 30, 2025

#7903 (comment)
The PR already removed part of the slots code
going to be a bit tricky to revert

@GuyAv46
Copy link
Collaborator

GuyAv46 commented Dec 30, 2025

@kei-nan right.
Maybe branch from 8.4, revert this PR, and then CP the rest of #7829.

kei-nan added a commit that referenced this pull request Dec 30, 2025
@kei-nan
Copy link
Collaborator Author

kei-nan commented Dec 30, 2025

@kei-nan right. Maybe branch from 8.4, revert this PR, and then CP the rest of #7829.

I the end opened a PR in 8.4 which reverts this PR after talking to Joan.
we should merge that one before we merge Joan's PR.

alonre24 added a commit to alonre24/redis that referenced this pull request Jan 26, 2026
**Bug Fixes:**

* [redis#7385](RediSearch/RediSearch#7385) Fix high temporary memory consumption when loading multiple search indexes from RDB
* [redis#7430](RediSearch/RediSearch#7430) Fix a potential deadlock in `FT.HYBRID` in cluster mode during updates.
* [redis#7454](RediSearch/RediSearch#7454) Fix a garbage collection performence regression
* [redis#7460](RediSearch/RediSearch#7460) Fix potential double-free in Fork GC error paths
* [redis#7455](RediSearch/RediSearch#7455) Fix internal cursors not being deleted promptly in cluster mode
* [redis#7667](RediSearch/RediSearch#7667) Fix a cursor logical leak upon dropping the index
* [redis#7796](RediSearch/RediSearch#7796) Fix a potential use-after-free when removing connections
* [redis#7792](RediSearch/RediSearch#7792) Fix string comparison for binary data with embedded NULLs in TOLIST reducer in FT.AGGREGATE
* [redis#7823](RediSearch/RediSearch#7823) Update `FT.HYBRID` to accept vector blobs only via parameters
* [redis#7903](RediSearch/RediSearch#7903) Fix a memory leak in Hybrid ASM
* [redis#8052](RediSearch/RediSearch#8052) Fix `FT.HYBRID` behavior when used with `LOAD *`
* [redis#8082](RediSearch/RediSearch#8082) Fix incorrect FULLTEXT field metric counts
* [redis#8089](RediSearch/RediSearch#8089) Fix an edge case in `CLUSTERSET` handling
* [redis#8152](RediSearch/RediSearch#8152) Fix configuration registration issues

**Improvements:**

* [redis#7427](RediSearch/RediSearch#7427) Enhance `FT.PROFILE` with vector search execution details
* [redis#7431](RediSearch/RediSearch#7431) Ensure full `FT.PROFILE` output is returned on timeout with RETURN policy
* [redis#7507](RediSearch/RediSearch#7507) Track timeout warnings and errors in INFO
* [redis#7576](RediSearch/RediSearch#7576) Track OOM warnings and errors in INFO
* [redis#7612](RediSearch/RediSearch#7612) Track `maxprefixexpansions` warnings and errors in INFO
* [redis#7960](RediSearch/RediSearch#7960) Persist query warnings across cursor reads
* [redis#7551](RediSearch/RediSearch#7551), [redis#7616](RediSearch/RediSearch#7616), [redis#7622](RediSearch/RediSearch#7622), [redis#7625](RediSearch/RediSearch#7625) Add runtime thread and pending-jobs metrics
* [redis#7589](RediSearch/RediSearch#7589) Support multiple slot ranges in `search.CLUSTERSET`
* [redis#7707](RediSearch/RediSearch#7707) Add `WITHCOUNT` support to `FT.AGGREGATE`
* [redis#7862](RediSearch/RediSearch#7862) Add support for subquery `COUNT` in `FT.HYBRID`
* [redis#8087](RediSearch/RediSearch#8087) Add warnings when cursor results may be affected by ASM and expose ASM warnings in `FT.PROFILE`
* [redis#8049](RediSearch/RediSearch#8049) Add logging for index-related commands
* [redis#8150](RediSearch/RediSearch#8150) Fix shard total profile time reporting in `FT.PROFILE`
YaacovHazan pushed a commit to redis/redis that referenced this pull request Jan 26, 2026
**Bug Fixes:**

* [#7385](RediSearch/RediSearch#7385) Fix high
temporary memory consumption when loading multiple search indexes from
RDB
* [#7430](RediSearch/RediSearch#7430) Fix a
potential deadlock in `FT.HYBRID` in cluster mode during updates.
* [#7454](RediSearch/RediSearch#7454) Fix a
garbage collection performence regression
* [#7460](RediSearch/RediSearch#7460) Fix
potential double-free in Fork GC error paths
* [#7455](RediSearch/RediSearch#7455) Fix
internal cursors not being deleted promptly in cluster mode
* [#7667](RediSearch/RediSearch#7667) Fix a
cursor logical leak upon dropping the index
* [#7796](RediSearch/RediSearch#7796) Fix a
potential use-after-free when removing connections
* [#7792](RediSearch/RediSearch#7792) Fix string
comparison for binary data with embedded NULLs in TOLIST reducer in
FT.AGGREGATE
* [#7704](RediSearch/RediSearch#7704) Use
asynchronous jobs for GC in SVS to accelerate execution
* [#7823](RediSearch/RediSearch#7823) Update
`FT.HYBRID` to accept vector blobs only via parameters
* [#7903](RediSearch/RediSearch#7903) Fix a
memory leak in Hybrid ASM
* [#8052](RediSearch/RediSearch#8052) Fix
`FT.HYBRID` behavior when used with `LOAD *`
* [#8082](RediSearch/RediSearch#8082) Fix
incorrect FULLTEXT field metric counts
* [#8089](RediSearch/RediSearch#8089) Fix an
edge case in `CLUSTERSET` handling
* [#8152](RediSearch/RediSearch#8152) Fix
configuration registration issues

**Improvements:**

* [#7427](RediSearch/RediSearch#7427) Enhance
`FT.PROFILE` with vector search execution details
* [#7431](RediSearch/RediSearch#7431) Ensure
full `FT.PROFILE` output is returned on timeout with RETURN policy
* [#7507](RediSearch/RediSearch#7507) Track
timeout warnings and errors in INFO
* [#7576](RediSearch/RediSearch#7576) Track OOM
warnings and errors in INFO
* [#7612](RediSearch/RediSearch#7612) Track
`maxprefixexpansions` warnings and errors in INFO
* [#7960](RediSearch/RediSearch#7960) Persist
query warnings across cursor reads
* [#7551](RediSearch/RediSearch#7551),
[#7616](RediSearch/RediSearch#7616),
[#7622](RediSearch/RediSearch#7622),
[#7625](RediSearch/RediSearch#7625) Add runtime
thread and pending-jobs metrics
* [#7589](RediSearch/RediSearch#7589) Support
multiple slot ranges in `search.CLUSTERSET`
* [#7707](RediSearch/RediSearch#7707) Add
`WITHCOUNT` support to `FT.AGGREGATE`
* [#7862](RediSearch/RediSearch#7862) Add
support for subquery `COUNT` in `FT.HYBRID`
* [#8087](RediSearch/RediSearch#8087) Add
warnings when cursor results may be affected by ASM and expose ASM
warnings in `FT.PROFILE`
* [#8049](RediSearch/RediSearch#8049) Add
logging for index-related commands
* [#8150](RediSearch/RediSearch#8150) Fix shard
total profile time reporting in `FT.PROFILE`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants