-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Exception during serialization may lead to receiving a response for a key other than was requested #2528
Comments
This is correct and a valid observation. We enqueue a command to be sent, then the encoder (within the channel pipeline) encodes the command to be sent to the Redis server. Any failure in the codec lead to exceptional completion of the command with the message:
Encoding happens very late in the process and without a rewrite of the entire processing mechanism, we do not have a chance to remove the command from the protocol queue. Custom codecs can be very handy, however they always run on the event loop thread and with a chance of exceptions, the protocol synchronization is going to be broken. |
Thanks for your reply @mp911de! Right now I'm trying to understand what would be the proper and elegant solution to handle this. Your message sounds like this is not an easy thing to fix, if possible at all with the current design. To make sure we don't encounter this behavior anymore we wrapped our codec with an "exception free" version of it. We are catching every exception during serialization and fall back to storing an "empty" value in the cache. Then when reading the data back we check if the value we received is "empty" and if so, then consider that there was no value at all instead of trying to deserialize it. While this works, we still see this as a suboptimal solution because we now have to remember to use that "exception free" codec, and now we have to potentially store some useless data in our Redis. Do you have any idea what other workaround could be implemented to make sure we don't encounter any discrepancies? I'm not sure if we can "close" the cache client when an exception is thrown, but even if so, we are handling multiple thousand requests per second and this brief period of time when we potentially could have discrepancies is sensitive for us. In general, any insight on your plans on this would be very helpful for us to understand if there is a chance to expect a fix for this in foreseeable future. Thanks! |
The system isn't broken so there's nothing to fix. The core idea here is that a codec should always be able to encode its value unless clearly, the system runs out of memory. We're talking encoding at the level of When codecs operate on the level of object graphs, translating these into JSON or use JDK serialization, a whole new category of errors becomes possible. These cannot be handled by the Lettuce driver. It makes sense to include this information in the docs (wiki). From my perspective, this issue is resolved as it isn't actionable anymore. |
Docs are updated now, see https://github.com/lettuce-io/lettuce-core/wiki/Codecs#exception-handling-during-encoding |
Bug Report
Current Behavior
Hello maintainers. We've been trying to figure out one bug for a long time, but now I can reproduce it reliably.
When using an async client (happens both in Redis Cluster and standalone modes), it is possible to start receiving responses for different keys that were requested. This happens when
encodeValue
throws an exception in a concurrent environment.The sequence is as follows:
Stack trace
Input Code
I have a reproducer project (in Scala) here - https://github.com/serejja/lettuce-reproducer. You would need Scala SBT (https://www.scala-sbt.org/) to run it via
sbt run
Expected behavior/code
Even though the exception says the connection may be out of sync, my understanding is that you should never get the response for another key. Another question is why Lettuce doesn't close the connection on its own and just logs this message
Environment
redis:6-alpine
docker image. Also AWS ElastiCache Redis 7.0.7Possible Solution
Additional context
The text was updated successfully, but these errors were encountered: