You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Receiving rendered redis blob instead of string content on high memory pressure #2913
While testing the StackExchange.Redis library (on HGETALL api) under high memory pressure to induce frequent OutOfMemory exceptions, I encountered cases where the returned string value was a hexadecimal representation of the Redis response bytes (e.g., "4C-E8-3A...") instead of valid data. Notably, the client API did not report any error in these scenarios.
The conversion uses a try/catch block that, on any exception, returns the hex string. Is there a specific reason or intended purpose for this approach?
This forces us to check the validity of the values returned by the library, which makes things complicated.
Why not let the exception be thrown?
That is solving the wrong problem. It is fairly normal and expected for BLOBs to be Redis payloads, and it is meaningful and useful to have a tostring that renders that.
The real problem here is that somehow we (meaning: me) screwed up the results and gave you corrupted data. I've seen multiple reports of this, and it is highly critical to fix this ASAP.
Good news: I have now joined Redis on the client library team, so fixing this is literally my day job. I consider this to be top priority, so: if there's anything you can share to help me repro this, I really really want to fix the underlying problem.
Reacted by Jean-Christophe Cura and Igor Malinovskiy
Just to introduce my context, i'm migrating from ServiceStack.Redis to StackExchange.Redis on a webapp in .Net Framework.
Some year ago, some user was seeing data from other ones in high memory pressure context, and i've found a bug in ServiceStack (old version) that make that socket buffer was badly cleanned on a OOM exception... so data was served to next redis query... (with connection pool mode).
To fix / diagnose i've writed a small program that create multiple threads and load the memory to get OOM exceptions. I'm cleanning it so i will share it with you on my git account.
So before migration to servicetack i need to be sure to not have the same problem on high memory pressure, so i've adapted the programme to use servicestack lib.
=> I found 3 problems:
1- The one i've described here, i receive rendered blob in place of the excpected string.
2- I receive the data asked from an other thread (did you prefer that i create an other issue for this one ?)
3- Some time HashGetAll return a null or empty arry, it's not expected, it should throw
The difficulty is that it generate random OOM exception so not always reproduce the tow problems.
(I update the title of thi issue and come bak to you when the program is ready)
changed the title [-]Invalid data on high memory pressure[/-][+]Receiving rendered redis blob instead of string content on high memory pressure[/+]on Jul 21, 2025
Yes some time it take long other time not...
For this issue with blob rendered, you must give the argument checkContent (donet run checkContent) to reproduce.
Well, I left my laptop alone for a few hours trying to repro this - penultimate time of checking: no repro, came back a bit later: I'd exploded the OS with BTRFS failures. So that was fun. Will try again tomorrow.
I'm in an Hyper-V VM, the hoster is a windows 2011 enterprise, and the VM where the test run is windows 2022 server (VM with 50G memory and 16 logical processors).
It need to run quick, for example when i enable logs, it's more difficult to reproduce, all depends on where the random OutOfMemory occure...
Well, the "good" news is that it seems to fairly reliably break on Windows very quickly (repeatedly under 30s); that gives me something to work with, at least; thanks.
My plan starts with hacking out any memory reuse in, for example, the deframing arena, network buffers, etc, to see if we can find a smoking gun. I'm cautiously hopeful that this is all my fault, which is fine: I can fix things - my worry is that there's an underlying framework snafu in, for example, pooling, GC or network-stack; that will be harder to rectify.
OK, cool.
You can also add the log parameter (MemoryTester.exe checkcontent log) it will trace all different stack and exception type found, it can help
For this issue only in RedisValue class where you try/catch the GetString call, i can see that the GetString only call the Encoding.UTF8.GetString api.
I expect that only the case ArgumentOutOfRangeException need to return the rendered blob because of not convertible to UTF8 string, and for other exceptions just re-throw it so caller is notified of a problem, like OutOfMemory?
I've fixed in this way in a branch to continue testing without this render error: jcaspes@75b3013
Do you have any estimation for the delivery of the fix? It would really help us with our planning on our side.
Thanks again for addressing this issue as a high priority 👍
It is basically my main priority at the moment; note that enabling high-integrity mode (see docs) seems to be an effective temporary mitigation, but: I fully acknowledge that this is not a fix.
Short version: we fully know that something is broken here, that seems to be especially problematic in low-memory scenarios, but we have not fully isolated a cause. There's two streams of work:
try to see if we can identify the exact cause, and mitigate - most likely culprits are the arena allocator and the pipelines code
push ahead with separate unrelated proposed changes that remove both of the above entirely
In a perfect world, we'd get both implemented, so "1" lands in 2.* and "2" lands in 3.*. My investigations into both 1 & 2 continue. Unfortunately, it is hard to give an ETA on finding an exotic bug.
Hi,
If you look my memorytest commandline code, i've already tested the high-integrity mode, but unfortunately, that doesn't fix the problem, setting this parameter to true do not avoid errors.
By looking the highintegrity code, i see that it send an ECHO message prior to the asked command and check the response. if this do not fix, it certainly means that it's the bottom layer that's causing the issues.
I will soon have more time to digg on theses issues, If you have any ideas to explore, feel free to share them :-)
I've now time to work on these issues has my enterprise really want to migrate to StackExchange.Redis lib and gave us time to help on issues i've created and that are blocking the usage of the lib for security reason.
For the current issue #2913 and not the 2 other one #2919 and #2920 I think that the fix i propose in this PR is necessary, here an explanation:
Current is not a problem of corrupted data.
Even if data is not corrupted, during high memory pressure the call to Encoding.UTF8.GetString can throw an OutOfMemory exception like everywhere where the code allocates memory. In this case we will receive the hex value because of the try/catch(*), i really think that it is not a good idea to catch all kind of exception here.
Activity
mgravell commentedon Jul 19, 2025
That is solving the wrong problem. It is fairly normal and expected for BLOBs to be Redis payloads, and it is meaningful and useful to have a tostring that renders that.
The real problem here is that somehow we (meaning: me) screwed up the results and gave you corrupted data. I've seen multiple reports of this, and it is highly critical to fix this ASAP.
Good news: I have now joined Redis on the client library team, so fixing this is literally my day job. I consider this to be top priority, so: if there's anything you can share to help me repro this, I really really want to fix the underlying problem.
jcaspes commentedon Jul 21, 2025
Hello, ok, i undertand the need.
Just to introduce my context, i'm migrating from ServiceStack.Redis to StackExchange.Redis on a webapp in .Net Framework.
Some year ago, some user was seeing data from other ones in high memory pressure context, and i've found a bug in ServiceStack (old version) that make that socket buffer was badly cleanned on a OOM exception... so data was served to next redis query... (with connection pool mode).
To fix / diagnose i've writed a small program that create multiple threads and load the memory to get OOM exceptions. I'm cleanning it so i will share it with you on my git account.
So before migration to servicetack i need to be sure to not have the same problem on high memory pressure, so i've adapted the programme to use servicestack lib.
=> I found 3 problems:
1- The one i've described here, i receive rendered blob in place of the excpected string.
2- I receive the data asked from an other thread (did you prefer that i create an other issue for this one ?)
3- Some time HashGetAll return a null or empty arry, it's not expected, it should throw
The difficulty is that it generate random OOM exception so not always reproduce the tow problems.
(I update the title of thi issue and come bak to you when the program is ready)
[-]Invalid data on high memory pressure[/-][+]Receiving rendered redis blob instead of string content on high memory pressure[/+]jcaspes commentedon Jul 21, 2025
Hey,
I've added the program in a fork here:
https://github.com/jcaspes/StackExchange.Redis/tree/MemoryTester/toys/MemoryTester
I will add the two other cases i have detected in new issues
Don't hesitate if you need more informations
mgravell commentedon Jul 21, 2025
Thanks, I've pulled that down; no luck with a repro yet, but I guess it may take some time...
jcaspes commentedon Jul 21, 2025
Yes some time it take long other time not...
For this issue with blob rendered, you must give the argument checkContent (donet run checkContent) to reproduce.
mgravell commentedon Jul 21, 2025
Well, I left my laptop alone for a few hours trying to repro this - penultimate time of checking: no repro, came back a bit later: I'd exploded the OS with BTRFS failures. So that was fun. Will try again tomorrow.
Question: what OS are you seeing this on?
jcaspes commentedon Jul 21, 2025
I'm in an Hyper-V VM, the hoster is a windows 2011 enterprise, and the VM where the test run is windows 2022 server (VM with 50G memory and 16 logical processors).
It need to run quick, for example when i enable logs, it's more difficult to reproduce, all depends on where the random OutOfMemory occure...
jcaspes commentedon Jul 22, 2025
An other thing, i build in 32bit so memory limit in windows is 1.5Gb, it should not hang your computer
mgravell commentedon Jul 22, 2025
Ah, so it turns out that linux really, really doesn't want to run in 32-bit mode:
I'll dust off my Windows hardware...
mgravell commentedon Jul 22, 2025
Well, the "good" news is that it seems to fairly reliably break on Windows very quickly (repeatedly under 30s); that gives me something to work with, at least; thanks.
My plan starts with hacking out any memory reuse in, for example, the deframing arena, network buffers, etc, to see if we can find a smoking gun. I'm cautiously hopeful that this is all my fault, which is fine: I can fix things - my worry is that there's an underlying framework snafu in, for example, pooling, GC or network-stack; that will be harder to rectify.
jcaspes commentedon Jul 22, 2025
OK, cool.
You can also add the log parameter (MemoryTester.exe checkcontent log) it will trace all different stack and exception type found, it can help
jcaspes commentedon Jul 22, 2025
For this issue only in RedisValue class where you try/catch the GetString call, i can see that the GetString only call the Encoding.UTF8.GetString api.
This api can only throw:
ArgumentException
The byte array contains invalid Unicode code points.
ArgumentNullException
bytes is null.
DecoderFallbackException
A fallback occurred (for more information, see Character Encoding in .NET)
I expect that only the case ArgumentOutOfRangeException need to return the rendered blob because of not convertible to UTF8 string, and for other exceptions just re-throw it so caller is notified of a problem, like OutOfMemory?
I've fixed in this way in a branch to continue testing without this render error:
jcaspes@75b3013
vverdier commentedon Aug 14, 2025
Hello, I'm a colleague of @jcaspes.
He's currently out of the office.
Just checking if there's any update on this issue.
Thanks!
mgravell commentedon Aug 14, 2025
Working on it, as a high priority.
vverdier commentedon Aug 20, 2025
Do you have any estimation for the delivery of the fix? It would really help us with our planning on our side.
Thanks again for addressing this issue as a high priority 👍
mgravell commentedon Aug 20, 2025
It is basically my main priority at the moment; note that enabling high-integrity mode (see docs) seems to be an effective temporary mitigation, but: I fully acknowledge that this is not a fix.
Short version: we fully know that something is broken here, that seems to be especially problematic in low-memory scenarios, but we have not fully isolated a cause. There's two streams of work:
In a perfect world, we'd get both implemented, so "1" lands in 2.* and "2" lands in 3.*. My investigations into both 1 & 2 continue. Unfortunately, it is hard to give an ETA on finding an exotic bug.
jcaspes commentedon Sep 12, 2025
Hi,
If you look my memorytest commandline code, i've already tested the high-integrity mode, but unfortunately, that doesn't fix the problem, setting this parameter to true do not avoid errors.
https://github.com/jcaspes/StackExchange.Redis/blob/fd470d1b5dc78900c84518b479a46ae84b20a442/toys/MemoryTester/Program.cs#L48
By looking the highintegrity code, i see that it send an ECHO message prior to the asked command and check the response. if this do not fix, it certainly means that it's the bottom layer that's causing the issues.
I will soon have more time to digg on theses issues, If you have any ideas to explore, feel free to share them :-)
jcaspes commentedon Sep 18, 2025
Hello @mgravell,
I've now time to work on these issues has my enterprise really want to migrate to StackExchange.Redis lib and gave us time to help on issues i've created and that are blocking the usage of the lib for security reason.
For the current issue #2913 and not the 2 other one #2919 and #2920 I think that the fix i propose in this PR is necessary, here an explanation:
Current is not a problem of corrupted data.
Even if data is not corrupted, during high memory pressure the call to
Encoding.UTF8.GetStringcan throw an OutOfMemory exception like everywhere where the code allocates memory. In this case we will receive the hex value because of the try/catch(*), i really think that it is not a good idea to catch all kind of exception here.mgravell commentedon Sep 19, 2025
On the exceptions: agreed, and your PR looks like it is heading in the right direction.
mgravell commentedon Sep 26, 2025
I've confirmed this with the current merged
mainstate; we'll get that released as soon as we can. Thanks for your input.mgravell commentedon Sep 26, 2025
Closed via 2.9.24