Skip to content

Comments

Fixes memory leak when the job crashes before it's freed#3178

Merged
madolson merged 7 commits intovalkey-io:unstablefrom
sarthakaggarwal97:fix-valgrind-error
Feb 16, 2026
Merged

Fixes memory leak when the job crashes before it's freed#3178
madolson merged 7 commits intovalkey-io:unstablefrom
sarthakaggarwal97:fix-valgrind-error

Conversation

@sarthakaggarwal97
Copy link
Contributor

@sarthakaggarwal97 sarthakaggarwal97 commented Feb 9, 2026

If there is a crash between the time the job is popped and freed, we technically leak memory. This change allows us to peek, and pop just before we are about to free the job.

Fixes valgrind errors: https://github.com/valkey-io/valkey/actions/runs/21969557125/job/63467641572#step:6:8648

@sarthakaggarwal97 sarthakaggarwal97 added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Feb 9, 2026
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (fd57c21) to head (971258f).
⚠️ Report is 10 commits behind head on unstable.

Additional details and impacted files
@@       Coverage Diff        @@
##   unstable   #3178   +/-   ##
================================
================================
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot removed the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Feb 9, 2026
@sarthakaggarwal97
Copy link
Contributor Author

@madolson looks like valgrind is green with this PR: https://github.com/sarthakaggarwal97/valkey/actions/runs/21770227707

Do you have any feedbacks on this change on a high level? I know we discussed that this is a bit inefficient.

@sarthakaggarwal97 sarthakaggarwal97 marked this pull request as ready for review February 11, 2026 23:04
@sarthakaggarwal97
Copy link
Contributor Author

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Copy link
Member

@Nikhil-Manglore Nikhil-Manglore left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
@madolson madolson merged commit 051a5eb into valkey-io:unstable Feb 16, 2026
56 checks passed
harrylin98 pushed a commit to harrylin98/valkey_forked that referenced this pull request Feb 19, 2026
)

If there is a crash between the time the job is popped and freed, we
technically leak memory. This change allows us to peek, and pop just
before we are about to free the job.

Fixes valgrind errors:
https://github.com/valkey-io/valkey/actions/runs/21969557125/job/63467641572#step:6:8648

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
@JimB123
Copy link
Member

JimB123 commented Feb 23, 2026

@madolson Good to see that this change resolves the test issue.

However, I'm not keen on the API change. It's common/typical for a mutex queue to support multiple readers. By adding a peek API, it becomes confusing for this common case. A second reader can pop the item that was peeked - or 2 readers can peek the same thing.

I'll look into alternatives.

@madolson
Copy link
Member

However, I'm not keen on the API change. It's common/typical for a mutex queue to support multiple readers. By adding a peek API, it becomes confusing for this common case. A second reader can pop the item that was peeked - or 2 readers can peek the same thing.

Another thing we considered was to have a global/static pointer which keeps track of the per-thread objects. So even when the thread is killed, there is still a global reference so valgrind is happy.

I am indifferent to the new API, but we needed a fix for the valgrind issue.

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.

4 participants