Add middleware to ensure Router only handles errors for its clients #310
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.
If you nest usages of RedisClient (perhaps becuase you're scanning from one client whilst inserting into a different cluster, perhaps), it's possible for errors which were raised from one cluster's RedisClients to instead be handled by the wrong cluster.
This is bad, because it can mean processing bogus topology "updates" when e.g. MOVED or ASKING responses get caught by the wrong client.
To fix this, we can add a middleware to our RedisClient instances (through the documented middleware interface), and tag errors at the source based on what config object they came from. This can then be used inside the router to identify errors that it should and should not handle.
Although at the moment you have to try pretty hard to get into this situation (
sscan
andhscan
are probably the main ways to get it), solving this is important for my plan for transaction support. Recall that last year one of the reasons I wanted to wrap the returnedRedisClient
instances from#with
in a proxy was to make sure they didn't leak errors to each other: #298 (comment)If we do this in RedisClient middleware instead, we can identify errors correctly right at the source, and that should make it safe to pass the raw
RedisClient
instances to callers, removing the need for a proxy over the top of it.