question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrading from v0.11.x to Custom Serializers with RedisCacheLayer breaks existing caches

See original GitHub issue

What does the bug do?

The new Protobuf serializer breaks upgrade path from 0.11.x to latest when used in conjunction with the Redis layer

ProtoBuf.ProtoException: Invalid wire-type (Varint); this usually means you have over-written a file without truncating or setting the length; see https://stackoverflow.com/q/2152978/23354
   at ProtoBuf.ProtoReader.State.ThrowProtoException(String message) in /_/src/protobuf-net.Core/ProtoReader.State.ReadMethods.cs:line 770
   at ProtoBuf.ProtoReader.State.ThrowWireTypeException() in /_/src/protobuf-net.Core/ProtoReader.State.ReadMethods.cs:line 763
   at proto_8(State& , CachedFeature )
   at ProtoBuf.ProtoReader.State.ReadMessage[TSerializer,T](SerializerFeatures features, T value, TSerializer& serializer)
   at proto_6(State& , CacheEntry`1 )
   at ProtoBuf.ProtoReader.State.ReadAsRoot[T](T value, ISerializer`1 serializer)
   at ProtoBuf.ProtoReader.State.DeserializeRoot[T](T value, ISerializer`1 serializer)
   at ProtoBuf.Serializer.Deserialize[T](Stream source)
   at CacheTower.Providers.Redis.RedisCacheLayer.GetAsync[T](String cacheKey)
   at CacheTower.CacheStack.GetWithLayerIndexAsync[T](String cacheKey)
   at CacheTower.CacheStack.GetOrSetAsync[T](String cacheKey, Func`2 valueFactory, CacheSettings settings)
   at CacheTower.CacheStack`1.GetOrSetAsync[T](String cacheKey, Func`3 getter, CacheSettings settings)

How can it be reproduced?

Generate some caches in a redis layer on 0.11.3 Update CacheTower to latest Read caches

Diagnostic

I believe the issue stems from the fact that historically this wrapper was used when persisting items to the redis cache layer

https://github.com/TurnerSoftware/CacheTower/pull/172/files#diff-972f6f8307717fcd20b6599842d83ab73931e2aa4b483e5076ab39d5f5109e0dL13

Now, CacheEntry’T is used directly.

I’m not quite sure how this type serializes without the ProtoXXX attributes on the class, but magically it does. Unfortunately, it isn’t binary compatible with RedisCacheEntry and things go bang.

Obviously we could consider purging the cache to solve the issue, but the problem is more significant for us as we have a wide range of services, and we would have to take everything offline, update them all, purge old caches, then bring it all back up again in order to update.

Any ideas would be appreciated!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:32 (31 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikPilsits-RJWcommented, Feb 27, 2023

@Turnerj We just got hit by this as well on a clear cache instance. I found one of our developers had added an explicit reference to protobuf-net in a project in order to get the model attributes (ProtoContract etc). Versions > 3.1.22 now throw during the serializer constructor (I’m assuming that’s when protobuf-net changed behavior per your bug report). This was not easy to track down so we’d really appreciate a CacheTower update to fix this.

1reaction
mgoodfellowcommented, Oct 13, 2022

Very interesting! Thanks for the investigation, glad we have an answer for the strangeness now.

There isn’t any rush for the changes, I was only just getting around to upgrading (finally!) from 0.11.3! Thanks for taking the time to look at the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found