Fix issues in valkeyClusterAsyncCallback#306
Open
bjosv wants to merge 3 commits intovalkey-io:mainfrom
Open
Conversation
If valkeyClusterGetValkeyAsyncContext returns NULL for MOVED, it falls through to goto retry with ac_retry == NULL, which would crash in valkeyAsyncFormattedCommand. The ASK case handles this, but MOVED doesn't. Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
cc is the address of a struct member (&acc->cc). It can never be NULL unless acc itself is at address 0, which was already checked. This is dead code that suggests a misunderstanding. Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
Restructure valkeyClusterAsyncCallback to use a single exit path ensuring the user callback is always invoked on a failure instead of being silently dropped when: - The ASKING command failed to send - The retry valkeyAsyncFormattedCommand failed Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
zuiderkwast
reviewed
Apr 24, 2026
Collaborator
zuiderkwast
left a comment
There was a problem hiding this comment.
I haven't read the logic carefully yet but I found some mistakes.
Comment on lines
+2956
to
+2958
| assert(cad != NULL); | ||
| if (cad == NULL) | ||
| return; |
Collaborator
There was a problem hiding this comment.
assert + if...? Pick one.
Collaborator
Author
There was a problem hiding this comment.
Its due to NDEBUG, get asserts in debug builds and tests, but don't crash in release builds.
Maybe its not worth it? I believe we have some legacy code like it
Comment on lines
+2961
to
2962
| assert(acc != NULL); | ||
| if (acc == NULL) { |
Collaborator
There was a problem hiding this comment.
Same here; either assert or if, not both.
Comment on lines
+2970
to
+2972
| assert(command != NULL); | ||
| if (command == NULL) | ||
| goto done; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix several issues in the async cluster command callback:
If
valkeyClusterGetValkeyAsyncContextfailed after a MOVED redirect,ac_retrywas used without a NULL check, causing a crash.When a retry send or ASKING command failed, the user callback was never invoked, leaving the caller unaware of the failure and unable to clean up
privdata.&acc->cc.Also restructured the function to use a single exit path, eliminating the
retry:anderror:goto labels and making the control flow easier to follow. Added asserts to document invariants and a function-level doc comment.