Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8ef3fa6

Browse files
committed
Add notes on Debugging Data Corruption Issues
1 parent f3ca9cd commit 8ef3fa6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,30 @@ daysOfWeek.PrintDump(); //[Sunday, Monday, Tuesday, ...]
761761
More examples can be found in the [Redis Eval Lua tests](https://github.com/ServiceStack/ServiceStack.Redis/blob/master/tests/ServiceStack.Redis.Tests/RedisClientEvalTests.cs
762762
)
763763

764+
### Debugging Data Corruption Issues
765+
766+
An issue that can be hard to debug is if the same `RedisClient` instance is shared across multiple threads which can result in returning corrupted data.
767+
Typically this is a result of using `IRedisClient` field in a singleton instance or sharing it as a static instance. To prevent this, each Thread that
768+
uses Redis should retrieve the redis client within a using statement, e.g:
769+
770+
```csharp
771+
using (var redis = redisManager.GetClient())
772+
{
773+
//..
774+
}
775+
```
776+
777+
Unfortunately the call-site which returns the corrupted response or runtime Exception doesn't identify where else the Redis client instance was being used.
778+
To help identify where client instances are being used you can assert that the client is only used in the Thread that resolved it from the pool with:
779+
780+
```csharp
781+
RedisConfig.AssertAccessOnlyOnSameThread = true;
782+
```
783+
784+
This captures the Thread's StackTrace each time the client is resolved from the pool which as it adds a lot of overhead, should only be enabled when debugging connection issues.
785+
786+
If it does detect the client is being accessed from a different thread it will throw a `InvalidAccessException` with the message containing the different **Thread Ids** and the **original StackTrace** where the client was resolved from the pool. You can compare this with the StackTrace of the Exception to hopefully identify where the client is being improperly used.
787+
764788
## Copying
765789

766790
Since September 2013, ServiceStack source code is available under GNU Affero General Public License/FOSS License Exception, see license.txt in the source. Alternative commercial licensing is also available, see https://servicestack.net/pricing for details.

0 commit comments

Comments
 (0)