Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization / deserialization is not thread safe #921

Open
alxmitch opened this issue Apr 2, 2024 · 2 comments
Open

Serialization / deserialization is not thread safe #921

alxmitch opened this issue Apr 2, 2024 · 2 comments

Comments

@alxmitch
Copy link

alxmitch commented Apr 2, 2024

Describe the bug
Concurrently deserializing or serializing the same type from multiple threads can fail. Example stack trace:

Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.

   at System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported()
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at YamlDotNet.Serialization.ObjectFactories.DefaultObjectFactory.GetStateMethods(Type attributeType, Type valueType)
   at YamlDotNet.Serialization.ObjectFactories.DefaultObjectFactory.ExecuteState(Type attributeType, Object value)
   at YamlDotNet.Serialization.ObjectFactories.DefaultObjectFactory.ExecuteOnDeserializing(Object value)
   at YamlDotNet.Serialization.NodeDeserializers.ObjectNodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)

To Reproduce
Serialize / deserialize objects of the same type from multiple threads using the same Serializer / Deserializer
See kubernetes-client/csharp#1537

@alxmitch
Copy link
Author

alxmitch commented Apr 2, 2024

#920

@filzrev
Copy link

filzrev commented Apr 3, 2024

Add related discussion link (#844)

Currently I'm using the ThreadLocal<ISerializer> workaround though.
I'd appreciate if a thread-safe implementation is also supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants