Our trade portal is a Spring Boot application on eight pods, with sessions stored in Redis through Spring Session so a customer can land on any pod. A release in October added one field to the customer context object we keep in the session: the depot a customer prefers to collect from. The rollout started at ten past eleven, one pod at a time.
Within two minutes customers with an open session started getting error pages, on some clicks and not on others. The logs had java.io.InvalidClassException: local class incompatible, stream classdesc serialVersionUID differs from the local class.
Spring Session's default serializer for Redis is plain Java serialization. A Serializable class with no explicit serialVersionUID gets one computed from its structure, so adding a field gives it a different value, and Java refuses to read a stream written with another. During the rollout, whichever version wrote a session last, the other version could not read it. Each customer's next click was a coin toss between an old pod and a new one.
We rolled back. It made things worse. By then the new pods had rewritten thousands of sessions, the old version could not read any of them, and now every pod was old. Neither version could read what the other had written, and backwards was no safer than forwards.
The fix that afternoon used serialver, a tool in the JDK that prints the serialVersionUID a class would get. We ran it against the class in the previous release, pinned that value in the new class and released again. Java serialization treats an added field as a compatible change when the identifiers match, and the new field simply arrived empty from old sessions. The errors stopped as the release completed.
Since then every serializable class in the portal declares its serialVersionUID, and a build check fails on one that does not. Sessions are now serialized as JSON, through a bean named springSessionDefaultRedisSerializer, with unknown fields ignored. We switched serializers early on a Sunday morning and accepted that everyone had to sign in again once. The release pipeline has a test that writes a session with the previous release and reads it with the new one, and the other way round.
Any data shared between two versions of an application is an interface between them, whether or not anybody designed it as one.
– Sergey Shinder
Top comments (0)