Skip to content

Fix module commandresult event cleanup during unsubscribe and module unload#3545

Merged
hpatro merged 6 commits into
valkey-io:unstablefrom
sarthakaggarwal97:fix/commandresult-only-fix
Apr 24, 2026
Merged

Fix module commandresult event cleanup during unsubscribe and module unload#3545
hpatro merged 6 commits into
valkey-io:unstablefrom
sarthakaggarwal97:fix/commandresult-only-fix

Conversation

@sarthakaggarwal97

@sarthakaggarwal97 sarthakaggarwal97 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

This follows up on the commandresult API work and fixes cleanup around unsubscribe and module unload.

The main issue was that command-result event listeners could leave stale state behind. On unload, we removed the listeners themselves but didn’t fully update the fast-path listener counters. Separately, unsubscribing with a NULL callback could behave badly if the listener wasn’t present anymore. In practice, that meant later commands could still walk into command-result event handling after the module was supposed to be cleaned up.

Failed in Daily as well yesterday: https://github.com/valkey-io/valkey/actions/runs/24753491944/job/72421581610#step:10:852
Related Failures: #2936 (comment)

Signed-off-by: Sarthak Aggarwal <25262500+sarthakaggarwal97@users.noreply.github.com>
@sarthakaggarwal97 sarthakaggarwal97 force-pushed the fix/commandresult-only-fix branch from 9460812 to 95f6e0f Compare April 22, 2026 20:09
@sarthakaggarwal97 sarthakaggarwal97 added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Apr 22, 2026
@sarthakaggarwal97 sarthakaggarwal97 changed the title Fix commandresult event cleanup Fix module commandresult event cleanup Apr 22, 2026
@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.37%. Comparing base (7db5b70) to head (acb858b).
⚠️ Report is 2 commits behind head on unstable.

Files with missing lines Patch % Lines
src/module.c 10.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #3545   +/-   ##
=========================================
  Coverage     76.37%   76.37%           
=========================================
  Files           159      159           
  Lines         80045    80054    +9     
=========================================
+ Hits          61133    61142    +9     
  Misses        18912    18912           
Files with missing lines Coverage Δ
src/module.c 25.31% <10.00%> (-0.05%) ⬇️

... and 21 files with indirect coverage changes

🚀 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.

@sarthakaggarwal97 sarthakaggarwal97 marked this pull request as ready for review April 22, 2026 20:43
@sarthakaggarwal97

Copy link
Copy Markdown
Contributor Author

@hpatro if you can help review this PR

@sarthakaggarwal97

Copy link
Copy Markdown
Contributor Author

@martinrvisser it would be really helpful if you can take a look!

@martinrvisser

Copy link
Copy Markdown
Contributor

@sarthakaggarwal97 thanks for fixing the stale counters and NULL callback guard. The change for ListFirst + next I don't think is strictly necessary as listNext already reads and saves current->next before returning current (adlist.c:262).

Comment thread src/module.c Outdated
Comment thread tests/modules/commandresult.c Outdated
Comment thread tests/unit/moduleapi/commandresult.tcl Outdated
Comment thread tests/unit/moduleapi/commandresult.tcl Outdated
Comment thread tests/unit/moduleapi/commandresult.tcl
@lucasyonge

Copy link
Copy Markdown
Contributor

@sarthakaggarwal97 Is it possible paste your dairy CI result here and we can make sure it can pass the test (I check the link you sent, I thought the error only happens in module api test, right?). Thanks

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
@sarthakaggarwal97

Copy link
Copy Markdown
Contributor Author

@lucasyonge here is the 100 passing runs for reply-schema-validator test: https://github.com/sarthakaggarwal97/valkey/actions/runs/24863141290/job/72793132621#step:9:4006

@hpatro hpatro changed the title Fix module commandresult event cleanup Fix module commandresult event cleanup during unsubscribe and module unload Apr 24, 2026
@hpatro hpatro merged commit d2db0c2 into valkey-io:unstable Apr 24, 2026
65 of 66 checks passed
sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 24, 2026
…unload (valkey-io#3545)

This follows up on the commandresult API work and fixes cleanup around
unsubscribe and module unload.

The main issue was that command-result event listeners could leave stale
state behind. On unload, we removed the listeners themselves but didn’t
fully update the fast-path listener counters. Separately, unsubscribing
with a NULL callback could behave badly if the listener wasn’t present
anymore. In practice, that meant later commands could still walk into
command-result event handling after the module was supposed to be
cleaned up.

Failed in Daily as well yesterday:
https://github.com/valkey-io/valkey/actions/runs/24753491944/job/72421581610#step:10:852
Related Failures:
valkey-io#2936 (comment)

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
madolson pushed a commit that referenced this pull request Apr 27, 2026
…unload (#3545)

This follows up on the commandresult API work and fixes cleanup around
unsubscribe and module unload.

The main issue was that command-result event listeners could leave stale
state behind. On unload, we removed the listeners themselves but didn’t
fully update the fast-path listener counters. Separately, unsubscribing
with a NULL callback could behave badly if the listener wasn’t present
anymore. In practice, that meant later commands could still walk into
command-result event handling after the module was supposed to be
cleaned up.

Failed in Daily as well yesterday:
https://github.com/valkey-io/valkey/actions/runs/24753491944/job/72421581610#step:10:852
Related Failures:
#2936 (comment)

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
…sers)

Removed valkey-io#3504, valkey-io#3545, valkey-io#3503 - these fix bugs introduced by valkey-io#3324, valkey-io#2936,

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
valkey-io#3392 respectively, all new in RC2. Users never experienced these bugs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants