Skip to content
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

Improve MultiplexedConnection Error Handling #699

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

jaymell
Copy link
Contributor

@jaymell jaymell commented Oct 23, 2022

Improve MultiplexedConnection Error Handling

It was recently discovered that aio::MultiplexedConnection
does not properly handle errors. If a command in the pipe fails,
responses from subsequent commands in the pipe are not processed
and will be returned to the next request issued on the connection,
with potentially catastrophic results. This fix ensures that
all pending commands in the pipe are processed before returning.

Fixes #698.

@jaymell jaymell requested a review from djc October 23, 2022 20:57
@jaymell jaymell force-pushed the multiplex-connection-error-handling branch 2 times, most recently from 749720a to b7348d9 Compare October 25, 2022 05:31
@jaymell jaymell marked this pull request as ready for review October 26, 2022 05:29
redis/src/aio.rs Outdated Show resolved Hide resolved
redis/src/aio.rs Outdated Show resolved Hide resolved
@jaymell jaymell force-pushed the multiplex-connection-error-handling branch 2 times, most recently from a3bd58f to 30e8578 Compare November 2, 2022 18:43
@jaymell
Copy link
Contributor Author

jaymell commented Nov 2, 2022

If this looks okay, I believe we should consider merging. I think the current MultiplexedConnection implementation could stand some refactoring, but #698 needs a quick fix, as it's a very serious issue that can occur not just with improperly constructed command Pipelines but also with properly constructed pipelines in which a single command fails due to infrastructure issues.

@jaymell jaymell requested a review from djc November 2, 2022 18:51
@jaymell jaymell force-pushed the multiplex-connection-error-handling branch 2 times, most recently from a50c3ca to 9ec146f Compare November 2, 2022 20:21
It was recently discovered that `aio::MultiplexedConnection`
does not properly handle errors. If a command in the pipe fails,
responses from subsequent commands in the pipe are not processed
and will be returned to the next request issued on the connection,
with potentially catastrophic results. This fix ensures that
all pending commands in the pipe are processed before returning.

Fixes redis-rs#698.
@jaymell jaymell force-pushed the multiplex-connection-error-handling branch from 9ec146f to 4ff5e81 Compare November 2, 2022 20:23
// Need to gather more response values
return;
}
Err(err) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

So do we typically expect other return items to come in even after an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I will admit that intuitively it's a bit scary, but this is how the other Connections (e.g., for aio::Connection, and for the sync Connection) and indeed the other redis libraries I've looked at handle the situation. Unless there's an issue parsing the commands properly, or a larger infrastructure issue, the commands will all be sent and responses will be returned.

Again, I think the API itself here is poor. We really should return Results for individual commands rather than all-or-nothing but this fix needs to happen irrespective of that.

Copy link

Choose a reason for hiding this comment

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

We really should return Results for individual commands rather than all-or-nothing but this fix needs to happen irrespective of that.

I actually was looking for a FromRedisValue implementation for Result for this reason 😄

You might consider adding that as an option rather than pushing Result onto every consumer of your pipe api? Fwiw it's nice to be able to assert that the whole thing worked else it is an error. But for some use cases a partial success is important and may be distinct from an overall pipe failure - hence, a FromRedisValue<Result...> impl which would even let someone decide if 1 part of the pipeline is resulty distinct from the overall pipe!

Copy link
Contributor

Choose a reason for hiding this comment

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

PR welcome? 😄

@djc djc merged commit 66fb8ee into redis-rs:main Nov 7, 2022
@jaymell jaymell mentioned this pull request Nov 28, 2022
@jaymell jaymell deleted the multiplex-connection-error-handling branch December 10, 2022 17:58
@jaymell jaymell mentioned this pull request Dec 11, 2022
5 tasks
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.

ConnectionManager misaligns subsequent commands when pipe() has wrongtype commands
3 participants