I got a service that uses ServiceStack.Redis for storing objects (serialized with JSON). There's a key that's updated with each HTTP request - the flow is simple: get value for the key, deserialize it to a list, add/remove items, write modified list back to Redis.
Recently, we noticed a problem - some of the keys will become corrupt (so they can't be deserialized). I don't know why.
Exception says Type definitions should start with a '{', expecting seralized type X, got string starting with: Y at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(Type type, String strType, EmptyCtorDelegate ctorFn, Dictionary'2 typeAccessorMap
.
I read other answers - most of them imply you get JSON data from another computer or you don't have control over how it was built. But I do.
We use only few types - most of the properties are simple ints, others are DateTime.
I have only one theory - multithreading is involved. But in that case, it should be "last-write-wins" and no corruption should occur. Anybody else saw that behaviour?
We're using ServiceStack 3.9.71 (latest release from 3.x series) with Redis 2.8.9. .NET 4.5 web application is hosted on Windows and Redis server is on Linux.
Asked
Active
Viewed 296 times
0

chester89
- 8,328
- 17
- 68
- 113
-
@mythz may be you have an idea? – chester89 Nov 30 '16 at 09:04
-
You've not provided the source code causing the issue or an example of the corrupted data which could show the result of a dirty connection, I'm assuming a race condition possibly the result of sharing a redis client instance across multiple threads, but who knows. In future please use the 'servicestack-bsd' tag for referring to v3 BSD library issues to avoid confusion with the latest redis client. – mythz Nov 30 '16 at 13:18
-
@mythz so if we share a connection between threads, it's a problem? – chester89 Nov 30 '16 at 13:21
-
Yes, please read the docs. A redis client instance (like most instances in .NET) is not threadsafe. Each thread should resolve their own instance from the threadsafe client managers. – mythz Nov 30 '16 at 13:23
-
@mythz I see. will do. thanks – chester89 Nov 30 '16 at 13:24
-
@mythz I see that `RedisClient` class is not thread-safe – chester89 Nov 30 '16 at 13:34