dolittle-obsolete / DotNET.Fundamentals

Reusable, fundamental abstractions and building blocks
http://www.dolittle.io
MIT License
4 stars 8 forks source link

Crash when converting propertybag to event - very hard to know what went wrong #247

Open TomasEkeli opened 4 years ago

TomasEkeli commented 4 years ago

Issue when getting an AggregateRoot, in the replaying of events. This is a current project in production. The events are deserialised to property bags, but a crash occurs when converting the propery bags to the type. The error is very hard to pin down as there is no way to know which event(s) fail, and why.

Stacktrace:

mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory.Build (Dolittle.PropertyBags.PropertyBag propertyBag) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:69 mono.js:2354 at Dolittle.PropertyBags.ImmutableTypeConstructorBasedFactory.Build (System.Type type, Dolittle.PropertyBags.IObjectFactory objectFactory, Dolittle.PropertyBags.PropertyBag source) [0x00038] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ImmutableTypeConstructorBasedFactory.cs:36 mono.js:2354 at Dolittle.PropertyBags.ObjectFactory.Build (System.Type type, Dolittle.PropertyBags.PropertyBag source) [0x00023] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ObjectFactory.cs:49 mono.js:2354 at Dolittle.PropertyBags.ObjectFactory.Build[T] (Dolittle.PropertyBags.PropertyBag source) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ObjectFactory.cs:55 mono.js:2354 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) mono.js:2354 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:391 mono.js:2354 --- End of inner exception stack trace --- mono.js:2354 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:401 mono.js:2354 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 mono.js:2354 at Dolittle.PropertyBags.TypeExtensions.ConstructEnumerable (System.Type enumerableType, Dolittle.PropertyBags.IObjectFactory factory, System.Object obj) [0x0011e] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/TypeExtensions.cs:67 mono.js:2354 at Dolittle.PropertyBags.PropertyBagExtensions.ConstructInstanceOfType (Dolittle.PropertyBags.PropertyBag pb, System.Type targetType, System.String pbKey, Dolittle.PropertyBags.IObjectFactory factory) [0x0008d] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagExtensions.cs:55 mono.js:2354 at Dolittle.PropertyBags.PropertyBagExtensions.ConstructInstanceOfType (Dolittle.PropertyBags.PropertyBag propertyBag, System.Reflection.ParameterInfo parameterInfo, Dolittle.PropertyBags.IObjectFactory factory) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagExtensions.cs:35 mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory+<>cDisplayClass3_1.<.ctor>b2 (Dolittle.PropertyBags.PropertyBag pb) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:45 mono.js:2354 at (wrapper delegate-invoke) System.Func2[Dolittle.PropertyBags.PropertyBag,System.Object].invoke_TResult_T(Dolittle.PropertyBags.PropertyBag) mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory.ToCtorArgs (Dolittle.PropertyBags.PropertyBag propertyBag) [0x00015] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:77 mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory.Build (Dolittle.PropertyBags.PropertyBag propertyBag) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:69 mono.js:2354 at Dolittle.PropertyBags.ImmutableTypeConstructorBasedFactory.Build (System.Type type, Dolittle.PropertyBags.IObjectFactory objectFactory, Dolittle.PropertyBags.PropertyBag source) [0x00038] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ImmutableTypeConstructorBasedFactory.cs:36 mono.js:2354 at events.uploads.sync_results_recorded_logging_factory.Build (System.Type type, Dolittle.PropertyBags.IObjectFactory object_factory, Dolittle.PropertyBags.PropertyBag source) [0x0004e] in C:\code\dolittle\CustomerProjects\Wilhelmsen-Waterproof\Source\measurement\events\uploads\sync_results_recorded.cs:71 mono.js:2354 at Dolittle.PropertyBags.ObjectFactory.Build (System.Type type, Dolittle.PropertyBags.PropertyBag source) [0x00023] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ObjectFactory.cs:49 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].ToCommittedEvent (Dolittle.Runtime.Events.Store.CommitSequenceNumber commitSequenceNumber, Dolittle.Runtime.Events.EventEnvelope event) [0x00017] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:135 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].FromCommits (Dolittle.Runtime.Events.Store.Commits commits) [0x0002c] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:126 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].ReApplyEvents (Dolittle.Runtime.Commands.Coordination.ICommandContext commandContext, T aggregateRoot) [0x00038] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:90 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor`1[T].Get (Dolittle.Runtime.Events.EventSourceId id) [0x000ab] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:67 mono.js:2354 at domain.uploads.sync_command_handler.Handle (domain.uploads.request_sync cmd) [0x00027] in C:\code\dolittle\CustomerProjects\Wilhelmsen-Waterproof\Source\measurement\domain\uploads\sync_command_handler.cs:22 mono.js:2354 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00081] in /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:401 mono.js:2354 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/external/corefx/src/Common/src/CoreLib/System/Reflection/MethodBase.cs:53 mono.js:2354 at Dolittle.PropertyBags.TypeExtensions.ConstructEnumerable (System.Type enumerableType, Dolittle.PropertyBags.IObjectFactory factory, System.Object obj) [0x0011e] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/TypeExtensions.cs:67 mono.js:2354 at Dolittle.PropertyBags.PropertyBagExtensions.ConstructInstanceOfType (Dolittle.PropertyBags.PropertyBag pb, System.Type targetType, System.String pbKey, Dolittle.PropertyBags.IObjectFactory factory) [0x0008d] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagExtensions.cs:55 mono.js:2354 at Dolittle.PropertyBags.PropertyBagExtensions.ConstructInstanceOfType (Dolittle.PropertyBags.PropertyBag propertyBag, System.Reflection.ParameterInfo parameterInfo, Dolittle.PropertyBags.IObjectFactory factory) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagExtensions.cs:35 mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory+<>cDisplayClass3_1.<.ctor>b2 (Dolittle.PropertyBags.PropertyBag pb) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:45 mono.js:2354 at (wrapper delegate-invoke) System.Func2[Dolittle.PropertyBags.PropertyBag,System.Object].invoke_TResult_T(Dolittle.PropertyBags.PropertyBag) mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory.ToCtorArgs (Dolittle.PropertyBags.PropertyBag propertyBag) [0x00015] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:77 mono.js:2354 at Dolittle.PropertyBags.PropertyBagToTypeInstanceFactory.Build (Dolittle.PropertyBags.PropertyBag propertyBag) [0x00000] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/PropertyBagToTypeInstanceFactory.cs:69 mono.js:2354 at Dolittle.PropertyBags.ImmutableTypeConstructorBasedFactory.Build (System.Type type, Dolittle.PropertyBags.IObjectFactory objectFactory, Dolittle.PropertyBags.PropertyBag source) [0x00038] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ImmutableTypeConstructorBasedFactory.cs:36 mono.js:2354 at events.uploads.sync_results_recorded_logging_factory.Build (System.Type type, Dolittle.PropertyBags.IObjectFactory object_factory, Dolittle.PropertyBags.PropertyBag source) [0x0004e] in C:\code\dolittle\CustomerProjects\Wilhelmsen-Waterproof\Source\measurement\events\uploads\sync_results_recorded.cs:71 mono.js:2354 at Dolittle.PropertyBags.ObjectFactory.Build (System.Type type, Dolittle.PropertyBags.PropertyBag source) [0x00023] in /Users/einari/Projects/Dolittle/Fundamentals/DotNET.Fundamentals/Source/PropertyBags/ObjectFactory.cs:49 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].ToCommittedEvent (Dolittle.Runtime.Events.Store.CommitSequenceNumber commitSequenceNumber, Dolittle.Runtime.Events.EventEnvelope event) [0x00017] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:135 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].FromCommits (Dolittle.Runtime.Events.Store.Commits commits) [0x0002c] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:126 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor1[T].ReApplyEvents (Dolittle.Runtime.Commands.Coordination.ICommandContext commandContext, T aggregateRoot) [0x00038] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:90 mono.js:2354 at Dolittle.Domain.AggregateRootRepositoryFor`1[T].Get (Dolittle.Runtime.Events.EventSourceId id) [0x000ab] in /Users/einari/Projects/Dolittle/Runtime/DotNET.SDK/Source/Domain/AggregateRootRepositoryFor.cs:67 mono.js:2354 at domain.uploads.sync_command_handler.Handle (domain.uploads.request_sync cmd) [0x00027] in C:\code\dolittle\CustomerProjects\Wilhelmsen-Waterproof\Source\measurement\domain\uploads\sync_command_handler.cs:22

I suspect the issue here is that one of the events contain as properties IEnumerables and the objects in the IEnumerable contain properties that are DateTimeOffsets. The values are stored in the EventStore as longs, and there seems to be a problem with that.

My work-around right now is to serialise the property bag to json and de-serialise to the correct event type in a IUserDefinedTypeFactory.

When failing to re-create events I think it's important to indicate which event failed and why to the logs - to help in mitigating the issue.

I also suspect that the BuildDateTimeOffset -method in the PropertyBagExtensions class should use Int64 instead of long.

┆Issue is synchronized with this Asana task

TomasEkeli commented 4 years ago

This might be an underlying issue? https://ericlippert.com/2009/03/03/representation-and-identity/