Skip to content

[MOD-10681] Fix cursor list empty#6594

Merged
lerman25 merged 9 commits intomasterfrom
omerL-fix_cursor_list_empty
Aug 6, 2025
Merged

[MOD-10681] Fix cursor list empty#6594
lerman25 merged 9 commits intomasterfrom
omerL-fix_cursor_list_empty

Conversation

@lerman25
Copy link
Copy Markdown
Collaborator

@lerman25 lerman25 commented Aug 4, 2025

Currently, CursorList_Empty does not acquire the CursorList_Lock, despite calling Cursor_FreeInternal, which requires it. This can lead to a use-after-free error, as observed in MOD-10681.

This PR addresses the issue by making CursorList_Empty thread-safe. It adopts the same logic used in Cursors_Purge:

  • If a cursor is idle, it is freed immediately.
  • If it is active, it is marked as deleted and will be safely freed on its next use.

This ensures correctness and safety in multi-threaded environments where cursor usage and cleanup may occur concurrently.

@lerman25 lerman25 requested review from GuyAv46 and Copilot August 4, 2025 16:26
@github-actions github-actions bot added the size:S label Aug 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a thread safety issue in CursorList_Empty that could lead to use-after-free errors. The fix ensures proper locking when freeing cursors and implements a safe cleanup strategy for active cursors.

  • Adds proper locking around cursor cleanup operations
  • Implements safe handling of active cursors by marking them for deletion instead of immediate freeing
  • Adopts the same logic pattern used in Cursors_Purge for consistency

Comment thread src/cursor.c
Comment thread src/cursor.c
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.46%. Comparing base (f0e15f2) to head (399beb4).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6594      +/-   ##
==========================================
- Coverage   87.48%   87.46%   -0.02%     
==========================================
  Files         277      277              
  Lines       45554    44515    -1039     
  Branches     6989     7450     +461     
==========================================
- Hits        39851    38934     -917     
+ Misses       5611     5476     -135     
- Partials       92      105      +13     
Flag Coverage Δ
flow 84.43% <87.50%> (+3.07%) ⬆️
unit 48.93% <100.00%> (+0.22%) ⬆️

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.

Copy link
Copy Markdown
Collaborator

@GuyAv46 GuyAv46 left a comment

Choose a reason for hiding this comment

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

Greate implementation

Comment thread src/cursor.c
Comment thread src/cursor.c
Comment thread src/cursor.h Outdated
Comment thread tests/cpptests/test_cpp_cursors.cpp
@github-actions github-actions bot added the size:M label Aug 5, 2025
Comment thread tests/cpptests/test_cpp_cursors.cpp Outdated
Comment thread tests/cpptests/test_cpp_cursors.cpp Outdated
@lerman25 lerman25 enabled auto-merge August 6, 2025 05:53
@lerman25 lerman25 added this pull request to the merge queue Aug 6, 2025
Merged via the queue into master with commit 188a741 Aug 6, 2025
26 checks passed
@lerman25 lerman25 deleted the omerL-fix_cursor_list_empty branch August 6, 2025 07:32
redisearch-backport-pull-request bot pushed a commit that referenced this pull request Aug 6, 2025
* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)
@redisearch-backport-pull-request
Copy link
Copy Markdown
Contributor

Successfully created backport PR for 2.8:

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Aug 6, 2025
* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)
@redisearch-backport-pull-request
Copy link
Copy Markdown
Contributor

Successfully created backport PR for 2.10:

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Aug 6, 2025
* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)
@redisearch-backport-pull-request
Copy link
Copy Markdown
Contributor

Successfully created backport PR for 8.2:

lerman25 added a commit that referenced this pull request Aug 6, 2025
* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find
github-merge-queue bot pushed a commit that referenced this pull request Aug 6, 2025
[MOD-10681] Fix cursor list empty (#6594)

* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)

Co-authored-by: lerman25 <58445352+lerman25@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Aug 6, 2025
* [MOD-10681] Fix cursor list empty (#6594)

* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)

* fix test

---------

Co-authored-by: lerman25 <58445352+lerman25@users.noreply.github.com>
Co-authored-by: lerman25 <lerman25@gmail.com>
github-merge-queue bot pushed a commit that referenced this pull request Aug 6, 2025
* [MOD-10681] Fix cursor list empty (#6594)

* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

(cherry picked from commit 188a741)

* fix test

---------

Co-authored-by: lerman25 <58445352+lerman25@users.noreply.github.com>
Co-authored-by: lerman25 <lerman25@gmail.com>
github-merge-queue bot pushed a commit that referenced this pull request Aug 6, 2025
* [MOD-10681] Fix cursor list empty (#6594)

* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find

* add missing includes

* handle Dict

* fix test

* fix use after free
JoanFM pushed a commit that referenced this pull request Apr 13, 2026
* fix cursorList_Empty to mark delete instead of instant delete

* remove redundant GC call

* remove unused destroy

* remove Destroy from h file

* update owernship test

* fix comments

* expand test to multiple cursors

* fix loop

* use std::vector and std::find
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.

3 participants