Skip to content

Potential Command Duplication in _send_command_parse_response Retry Mechanism #3554

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

Closed
ManelCoutinhoSensei opened this issue Mar 12, 2025 · 5 comments
Assignees

Comments

@ManelCoutinhoSensei
Copy link

Hi there,

I have a conceptual problem with how the _send_command_parse_response is being grouped:

redis-py/redis/client.py

Lines 590 to 595 in ea01a30

def _send_command_parse_response(self, conn, command_name, *args, **options):
"""
Send a command and parse the response
"""
conn.send_command(*args, **options)
return self.parse_response(conn, command_name, **options)

My issue is that this method is called inside a retry mechanism:

redis-py/redis/client.py

Lines 623 to 628 in ea01a30

return conn.retry.call_with_retry(
lambda: self._send_command_parse_response(
conn, command_name, *args, **options
),
lambda error: self._disconnect_raise(conn, error),
)

Which means that if the Redis container goes down after send_command and before parse_response, the entire _send_command_parse_response will be retried. This means that any command with side effects (such as XADD) could be executed twice instead of just once, leading to unintended duplication.

Would love to hear thoughts on potential fixes for this issue. Let me know if you need any additional details!

@vladvildanov
Copy link
Collaborator

vladvildanov commented Mar 13, 2025

Hi @ManelCoutinhoSensei ! You have a point here, it doesn't makes sense to retry write operation on read failure, moreover it may lead to unintended disconnects because we have a data in a socket buffer that we doesn't process. We would take this issue into a count

if connection.can_read() and self.cache is None:

@excitoon
Copy link
Contributor

If you don't want this "This means that any command with side effects (such as XADD) could be executed twice instead of just once, leading to unintended duplication." you need to either disable retries and handle them yourself or move all of that into repeatable transaction or whatever, in general case this is unsolvable problem.

@ManelCoutinhoSensei
Copy link
Author

@excitoon, your explanation suggests that the retry system's limitations force users to disable it and manage retries themselves. However, the solution proposed in PR 3559 demonstrates that the duplication issue can be resolved within the existing framework. While the PR may not be perfect, it shows that addressing this problem without abandoning the built-in retry mechanism is indeed feasible.
Furthermore, I don't know if it makes much sense for a library to have a functionality that ultimately doesn't work/is unreliable

@vladvildanov
Copy link
Collaborator

#3559 (comment)

@ManelCoutinhoSensei
Copy link
Author

Follow up here

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 a pull request may close this issue.

3 participants