Closed CrimsonKyle closed 7 years ago
Ok so we can go ahead and close this issue two of my models can potentially have the same primary key just finding this out now! So I was apparently trying to update a different type of object by the same primary key so it was confusing realm forgot that Realm's primary key has to be unique across all models is there any way a future enhancement could be model specific primary keys?
I'm not sure what you mean by "same primary key", but I don't think that's the cause of what you're seeing here. It appears to be related to notifying subscribers of PropertyChanged
.
Is there a way to suspend Notifications to subscribers while syncing?
Still only occurring on Android
@nirinchev is this being thrown from #985?
Nope, although it's similar. What we had there was collected objects throwing NRE. Here you have a notification that points to an object outside of the app domain which should never happen. The bad news is that we can neither catch nor guard against that case, so we have to figure out what's causing it. Can you consistently reproduce it with your setup?
Yep I can get it to fail 10/10 times on Android lol
Then I assume you can guess what's going to be my next request 😅 If you could send us a repro so we could attach a debugger, that would speed up the process immensely.
Sorry didn't mean to close this ill try to get the sample to replicate it
Or just get an NDA the only problem with sending you our solution is our web services are all currently internal so the app wouldn't actually work to the point where it breaks
Yes, that would be problematic :/ In that case, isolating a sample would be best, otherwise we'll have to settle for a very detailed description of what happens before the crash :)
So I am trying to wrap my head around this error to better debug it. Basically the CGHandle works with managed objects and the write is trying to Notify an object that is outside the domain of the app so that means it is not any of my bindings right?
Basically, when a managed object registers for notifications, we create a GCHandle for it and pass a pointer to that handle to native with information which is the native object we want to observe. Native keeps a list of objects it observes for notifications and stores the pointer for each of them. Then, when a notification occurs, it calls into managed code and passes the pointer it has previously stored, which we then use to reconstruct the GCHandle and get the object from it. What appears to be the problem is that somewhere along that chain, the pointer we're passing around starts pointing to memory outside the app domain.
And technically every realm result set is live to they are subscribed for notifications automatically right?
Nope - they are only subscribed if you pass them to a binding or if you manually call SubscribeForNotifications()
.
Ok thanks I am going to comment all those out in my code and start adding them back to pin down the exact case
Removed all SubscribeForNotifications() still same error next step is remove all list views that have a realm result bound to the data source right?
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) System.Runtime.InteropServices.GCHandle.CheckCurrentDomain (int) <0x00007>
[mono-rt] at System.Runtime.InteropServices.GCHandle.op_Explicit (intptr) [0x0001b] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:134
[mono-rt] at System.Runtime.InteropServices.GCHandle.FromIntPtr (intptr) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:176
[mono-rt] at Realms.RealmObject.NotifyRealmObjectPropertyChanged (intptr,intptr) [0x00001] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at (wrapper native-to-managed) Realms.RealmObject.NotifyRealmObjectPropertyChanged (intptr,intptr) [0x00022] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at <unknown> <0xffffffff>
[mono-rt] at (wrapper managed-to-native) Realms.SharedRealmHandle/NativeMethods.begin_transaction (Realms.SharedRealmHandle,Realms.NativeException&) <0x00007>
[mono-rt] at Realms.SharedRealmHandle.BeginTransaction () [0x00003] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at Realms.Transaction..ctor (Realms.Realm) [0x00013] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at Realms.Realm.BeginWrite () [0x00007] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at Realms.Realm.Write (System.Action) [0x00007] in <f0097c463d884e09ba2bde58b530c6d7>:0
[mono-rt] at AltecService.MergeLogic.CascadeingSRHistoryDelete (string) [0x000b0] in /Users/kmrichar/Documents/Git/altec-service/AltecService/Services/SyncGateway/GatewayLogic/MergeLogic.cs:191
[mono-rt] at AltecService.MergeLogic/<MergeServiceRequestHistory>c__async7.MoveNext () [0x00105] in /Users/kmrichar/Documents/Git/altec-service/AltecService/Services/SyncGateway/GatewayLogic/MergeLogic.cs:472
[mono-rt] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<AltecService.MergeLogic/<MergeServiceRequestHistory>c__async7> (AltecService.MergeLogic/<MergeServiceRequestHistory>c__async7&) [0x00031] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316
[mono-rt] at AltecService.MergeLogic.MergeServiceRequestHistory () [0x0001e] in <701fd4e6e6744daba4496a27ef850402>:0
[mono-rt] at AltecService.MergeLogic/<DestructiveMerge>c__async1.MoveNext () [0x000a0] in /Users/kmrichar/Documents/Git/altec-service/AltecService/Services/SyncGateway/GatewayLogic/MergeLogic.cs:299
[mono-rt] at System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner.InvokeMoveNext (object) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1089
[mono-rt] at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x0008d] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:957
[mono-rt] at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:904
[mono-rt] at System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner.Run () [0x0003b] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1070
[mono-rt] at System.Threading.Tasks.AwaitTaskContinuation.InvokeAction (object) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:741
[mono-rt] at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.Threading.ContextCallback,object,System.Threading.Tasks.Task&) [0x00017] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:770
[mono-rt] at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task,bool) [0x00016] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:419
[mono-rt] at System.Threading.Tasks.Task.FinishContinuations () [0x000cf] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:3649
[mono-rt] at System.Threading.Tasks.Task.FinishStageThree () [0x00045] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2366
[mono-rt] at System.Threading.Tasks.Task`1<System.Threading.Tasks.VoidTaskResult>.TrySetResult (System.Threading.Tasks.VoidTaskResult) [0x00058] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:488
[mono-rt] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<System.Threading.Tasks.VoidTaskResult>.SetResult (System.Threading.Tasks.VoidTaskResult) [0x0004b] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:608
[mono-rt] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<System.Threading.Tasks.VoidTaskResult>.SetResult (System.Threading.Tasks.Task`1<System.Threading.Tasks.VoidTaskResult>) [0x00019] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:636
[mono-rt] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult () [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:378
[mono-rt] at AltecService.MergeLogic/<MergeServiceRequests>c__async6.MoveNext () [0x00785] in /Users/kmrichar/Documents/Git/altec-service/AltecService/Services/SyncGateway/GatewayLogic/MergeLogic.cs:455
[mono-rt] at System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner.InvokeMoveNext (object) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1089
[mono-rt] at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x0008d] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:957
[mono-rt] at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:904
[mono-rt] at System.Runtime.CompilerServices.AsyncMethodBuilderCore/MoveNextRunner.Run () [0x0003b] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1070
[mono-rt] at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<s_postCallback>m__0 (object) [0x00000] in /Users/builder/data/lanes/4009/df84ee74/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:388
[mono-rt] at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/4009/3cde9f7c/source/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:35
[mono-rt] at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/3cde9f7c/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
[mono-rt] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/4009/3cde9f7c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:81
[mono-rt] at (wrapper dynamic-method) object.549486a2-a99b-4b9f-80ef-e59618e654ee (intptr,intptr) [0x00011] in <8c304e4006094a46a7950338a3b3cb5d>:0
[mono-rt] at (wrapper native-to-managed) object.549486a2-a99b-4b9f-80ef-e59618e654ee (intptr,intptr) [0x00021] in <8c304e4006094a46a7950338a3b3cb5d>:0
A little different now
Hi Kyle, I was able to identify an issue related to notifications which I hope was causing the crash you observed. Once the CI build passes, I'll grab the nuget and attach it here so you can verify it works for you.
Goal
Update a deeply nested object with the new version of the object by Primary Key on Android
Expected Results
Update the Object
Actual Results
Steps & Code to Reproduce
await _realm.WriteAsync(tempRealm => { var NewObject = new ServiceRequestHistory(); populate object tempRealm.Add(NewObject, true); });
Version of Realm and tooling
Realm version(s): 0.82.1
Xamarin/Visual Studio version: 6.2
Which operating system version and device: Android