Skip to content

Fix JedisBroadcastException in functionLoadReplace for Redis Cluster #4219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 14, 2025

Conversation

Kguswo
Copy link
Contributor

@Kguswo Kguswo commented Jul 31, 2025

Change Summary

Fix JedisBroadcastException in functionLoadReplace by restricting FUNCTION commands to primary nodes only.

As FUNCTION operations are write commands, they should not be broadcast to read-only replica nodes. This change updates the broadcast logic to filter primary nodes for these commands and adds tests to verify the behavior.

Open to suggestions or corrections!

Related Issue

Closes #4144

@ggivo ggivo self-requested a review August 11, 2025 06:07
PR redis#3306 introduces broadcasting of commands like FUNCTION DELETE, FUNCTION FLUSH, FUNCTION KILL, FUNCTION RESTORE ... to all nodes of the cluster. This leads to error when command is executed on non-writable (replica) node.

This commit introduces a fix to broadcast the commands only to primary nodes from the cluster.
Copy link
Collaborator

@ggivo ggivo left a comment

Choose a reason for hiding this comment

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

Hi @Kguswo,

Thank you for your contribution and for taking the time to work on this issue! 🙏

After reviewing your PR, I think the root cause of the problem goes back to the initial implementation when broadcasting was introduced (#3303). The original goal was to broadcast commands only to primary nodes, but it seems that currently we’re broadcasting them to all nodes. This affects all broadcasted commands, not just the FUNCTION subcommands.

To address this for all commands, we can introduce a cache of primary nodes (similar to your suggestion) and use that for all broadcasts—no need to filter by command for now. Since topology refreshes are relatively infrequent, it’s better to keep this primary-node cache updated after each topology change.

I’ve applied these changes directly in this PR so we can build on your work, and I’ll also ping the original requester of #3303 for review.

Thanks again for your effort—it’s much appreciated!

@ggivo ggivo removed the waiting-for-triage Still needs to be triaged label Aug 11, 2025
@ggivo ggivo added this to the 6.2.0 milestone Aug 11, 2025
@ggivo ggivo added the bug label Aug 11, 2025
@ggivo ggivo requested a review from uglide August 11, 2025 09:56
@ggivo
Copy link
Collaborator

ggivo commented Aug 11, 2025

This change is somewhat related to broadcasting changes in #4173
In my opinion, they are not contradicting. @uglide, could you also take a look?

Copy link
Contributor

@uglide uglide left a comment

Choose a reason for hiding this comment

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

LGTM. I will rebase my PR once it's merged. Thanks!

@ggivo ggivo merged commit 9187e24 into redis:master Aug 14, 2025
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JedisCluster functionLoadReplace throws JedisBroadcastException
3 participants