Convert to Hex only on Encoding.UTF8.GetString possible exceptions by jcaspes · Pull Request #2954 · StackExchange/StackExchange.Redis (original) (raw)
Issue #2913
Under high memory pressure, OutOfMemory exceptions can occure randomly on every line of code that allocate memory like in native Encoding.UTF8.GetString used by the tried call to Format.GetString(span);
Redis value conversion to string should not convert string in hex value on all possible exception but only when value is not a valid UTF8 byte array....
For this the catch will catch only possible exceptions thrown by Encoding.UTF8.GetString, this should not change the conversion behavior but will fix bad results in case of OutOfMemory exceptions or other not expected exceptions.
- Exception thrown by
Encoding.UTF8.GetStringfrom Microsoft documentation:
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)