Skip to content

MOD-10975: Fix fd leak when OOM#6672

Merged
nafraf merged 7 commits intomasterfrom
nafraf_fix-fd-leak
Aug 24, 2025
Merged

MOD-10975: Fix fd leak when OOM#6672
nafraf merged 7 commits intomasterfrom
nafraf_fix-fd-leak

Conversation

@nafraf
Copy link
Collaborator

@nafraf nafraf commented Aug 18, 2025

Describe the changes in the pull request

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

  1. Current:
    periodicCb() function returns early without closing the pipe file descriptors that were created.
  2. Change:
    Missing close() calls in the out-of-memory error path were added.
  3. Outcome:
    Fix fd leak

Main objects this PR modified

  1. ...

Mark if applicable

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

@nafraf nafraf requested review from meiravgri and raz-mon August 18, 2025 15:56
@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.46%. Comparing base (588fb97) to head (ad52f52).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6672      +/-   ##
==========================================
- Coverage   87.49%   87.46%   -0.04%     
==========================================
  Files         282      282              
  Lines       44838    44840       +2     
  Branches     7751     7751              
==========================================
- Hits        39231    39219      -12     
- Misses       5487     5501      +14     
  Partials      120      120              
Flag Coverage Δ
flow 84.50% <100.00%> (-0.16%) ⬇️
unit 49.26% <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 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.

meiravgri
meiravgri previously approved these changes Aug 19, 2025
@meiravgri
Copy link
Collaborator

Is it possible to test it?

raz-mon
raz-mon previously approved these changes Aug 19, 2025
Copy link
Collaborator

@raz-mon raz-mon left a comment

Choose a reason for hiding this comment

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

💪

@nafraf nafraf added this pull request to the merge queue Aug 19, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 19, 2025
Close pipe file descriptors in periodic callback to prevent resource leaks
@nafraf
Copy link
Collaborator Author

nafraf commented Aug 19, 2025

Is it possible to test it?

@meiravgri Using valgrind test I could not detect the leak, but running bash script it's possible to reproduce it and confirm the patch fix it. The script was posted to MOD-10975

@nafraf nafraf removed this pull request from the merge queue due to a manual request Aug 19, 2025
@nafraf nafraf dismissed stale reviews from raz-mon and meiravgri via 592fc66 August 19, 2025 18:36
@nafraf nafraf requested review from meiravgri and oshadmi August 19, 2025 19:46
oshadmi
oshadmi previously approved these changes Aug 20, 2025
@nafraf nafraf requested a review from raz-mon August 20, 2025 11:22
@nafraf nafraf added this pull request to the merge queue Aug 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 20, 2025
# Get open file count
redis_server_pid = env.executeCommand('info')['process_id']
open_files_before_gc = get_open_file_count(redis_server_pid)
env.assertGreater(open_files_before_gc, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this assertion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To confirm that we got the number of open files. I started implementing the test using psutil, and the test passed because it always returned 0 open files.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How do you know that there will be open fd's?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lsof -p <pid> counts all open file descriptors for the Redis process, including stdin, stdout, stderr, listening socket, and more.

Copy link
Collaborator Author

@nafraf nafraf Aug 24, 2025

Choose a reason for hiding this comment

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

But you are right, the CI failed. I'll check if lsof didn't work or if I need to remove the assertion.

@nafraf nafraf added this pull request to the merge queue Aug 21, 2025
@nafraf nafraf requested a review from oshadmi August 21, 2025 12:23
oshadmi
oshadmi previously approved these changes Aug 21, 2025
@nafraf nafraf enabled auto-merge August 21, 2025 12:34
@nafraf nafraf added this pull request to the merge queue Aug 24, 2025
@nafraf nafraf removed this pull request from the merge queue due to a manual request Aug 24, 2025
@nafraf nafraf added this pull request to the merge queue Aug 24, 2025
Merged via the queue into master with commit 56f6f0e Aug 24, 2025
17 checks passed
@nafraf nafraf deleted the nafraf_fix-fd-leak branch August 24, 2025 18:43
@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.8
git worktree add -d .worktree/backport-6672-to-2.8 origin/2.8
cd .worktree/backport-6672-to-2.8
git switch --create backport-6672-to-2.8
git cherry-pick -x 56f6f0ea603e422b8cf2288b328f877e4269d7da

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.6, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.6
git worktree add -d .worktree/backport-6672-to-2.6 origin/2.6
cd .worktree/backport-6672-to-2.6
git switch --create backport-6672-to-2.6
git cherry-pick -x 56f6f0ea603e422b8cf2288b328f877e4269d7da

@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.10, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.10
git worktree add -d .worktree/backport-6672-to-2.10 origin/2.10
cd .worktree/backport-6672-to-2.10
git switch --create backport-6672-to-2.10
git cherry-pick -x 56f6f0ea603e422b8cf2288b328f877e4269d7da

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Aug 24, 2025
* Close pipe file descriptors in periodic callback to prevent resource leaks

* Add open file count check in OOM test

* build_utils: factor out link_static_libraries() (#6673)

Will help implementing the iterator bencher.

* [MOD-10771] bump svs version (#6652)

* bump vecsim

* vecsim with fix

* test crash

* code change to trigger tests

* revert code chnage

* ci: pin a Rust nightly version (#6513)

Should prevent accidental breaking of the CI.

* get open fds using psutil.num_fds()

---------

Co-authored-by: Guillaume Desmottes <[email protected]>
Co-authored-by: meiravgri <[email protected]>
(cherry picked from commit 56f6f0e)
@redisearch-backport-pull-request
Copy link
Contributor

Successfully created backport PR for 8.2:

nafraf added a commit that referenced this pull request Aug 24, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 24, 2025
MOD-10975: Fix fd leak when OOM (#6672)

* Close pipe file descriptors in periodic callback to prevent resource leaks

* Add open file count check in OOM test

* build_utils: factor out link_static_libraries() (#6673)

Will help implementing the iterator bencher.

* [MOD-10771] bump svs version (#6652)

* bump vecsim

* vecsim with fix

* test crash

* code change to trigger tests

* revert code chnage

* ci: pin a Rust nightly version (#6513)

Should prevent accidental breaking of the CI.

* get open fds using psutil.num_fds()

---------



(cherry picked from commit 56f6f0e)

Co-authored-by: nafraf <[email protected]>
Co-authored-by: Guillaume Desmottes <[email protected]>
Co-authored-by: meiravgri <[email protected]>
nafraf added a commit that referenced this pull request Aug 24, 2025
nafraf added a commit that referenced this pull request Aug 24, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 28, 2025
MOD-10975: Fix fd leak when OOM (#6672)
(cherry picked from commit 56f6f0e)
github-merge-queue bot pushed a commit that referenced this pull request Sep 4, 2025
MOD-10975: Fix fd leak when OOM (#6672)
(cherry picked from commit 56f6f0e)
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.

6 participants