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

Exception when adding multiple documents to Realm via loop #6399

Closed
markstratman opened this issue Mar 20, 2023 · 6 comments · Fixed by #6962
Closed

Exception when adding multiple documents to Realm via loop #6399

markstratman opened this issue Mar 20, 2023 · 6 comments · Fixed by #6962
Assignees
Labels
O-Community Waiting-For-Reporter Waiting for more information from the reporter before we can proceed

Comments

@markstratman
Copy link

SDK and version

SDK : .Net Realm 10.20.0

Observations

  1. SubscribeForNotifications
  2. Performed 1000 adds via a loop, received the first 61 events the received crash report

Not always producible, about half the time a failure occures.

Crash log / stacktrace

D:\a\realm-dotnet\realm-dotnet\wrappers\realm-core\src\realm\alloc_slab.cpp:531: [realm-core-13.4.0] Assertion failed: ref + size <= next->first with (ref, size, next->first, next->second, get_file_path_for_assertions()) = [489768, 56, 489768, 56, "C:\Users\stratman\Documents\mongodb-realm\fleetproxy-szmau\64124734058eecc495c4658a\default.realm"]
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

C:\repo-git\wss\fleet-proxy\poc\dotnet\RealmClientConsole\RealmClientConsole\bin\Debug\net7\RealmClientConsole.exe (process 38392) exited with code -1073740791.

Steps & Code to Reproduce

        { 
            try
            {
                var realm = await GetRealmAsync();
                realm.Subscriptions.Update(() =>
                {
                    var myMoes = realm
                        .All<Moe>()
                        .Where(m => m.WjaProxyId == CurrentUser.Id);

                    myMoes
                        .SubscribeForNotifications(async (moes, changes, error) =>
                        {
                            try
                            {
                                if (changes != null)
                                {
                                    Console.ForegroundColor = ConsoleColor.Magenta;
                                    foreach (var i in changes.DeletedIndices)
                                    {
                                        Console.WriteLine($"Deleted moe id:{_moes[i]}");
                                    }

                                    foreach (var i in changes.InsertedIndices)
                                    {
                                        Console.WriteLine($"Inserted moe id:{moes[i].Id} deviceId:{moes[i].DeviceId} name:{moes[i].MoeName} value:{moes[i].MoeValue}");
                                    }

                                    foreach (var i in changes.NewModifiedIndices)
                                    {
                                        Console.WriteLine($"Modified moe id:{moes[i].Id} deviceId:{moes[i].DeviceId} name:{moes[i].MoeName} value:{moes[i].MoeValue}");
                                    }

                                    if (changes.IsCleared)
                                    {
                                        Console.WriteLine("Collection cleared");
                                    }
                                    Console.ResetColor();
                                    await SaveMoesAsync();
                                }
                            }
                            catch (Exception ex)
                            {
                                ShowException(ex);
                            }
                        });

                    var options = new SubscriptionOptions
                    {
                        Name = CurrentUser.Id,
                        UpdateExisting = true
                    };

                    realm
                        .Subscriptions
                        .Add(myMoes, options);
                });

                realm.All<Moe>().AsRealmCollection().CollectionChanged += HandleCollectionChanged;
                if (realm.SyncSession.ConnectionState != ConnectionState.Disconnected)
                {
                    await realm.Subscriptions.WaitForSynchronizationAsync();
                };
                Console.WriteLine("Subscription created");
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }

            public async Task addManyMoesAsync()
            {
                var start = getInteger("starting index");
                var end = getInteger("ending index");
                for(var i = start; i <= end; i++) 
                {
                    var value = i.ToString();
                    await AddAsync(value, value, value);
                }
            } 

        public static async Task AddAsync(string deviceId, string moeName, string moeValue)
        {
            try
            {
                var realm = await GetMainThreadRealmAsync();
                await realm.WriteAsync(() =>
                {
                    realm.Add(new Moe()
                    {
                        WjaProxyId = CurrentUser.Id,
                        DeviceId = deviceId,
                        MoeName = moeName,
                        MoeValue = moeValue
                    });
                });
                Console.WriteLine("Moe added");
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }```
@finnschiermer
Copy link
Contributor

Thanks for reporting this. A few initial questions:

  1. is it possible to open/inspect the realm file after this error has been reported?
  2. is this a local realm only scenario or is sync in use?
  3. is the realm file encrypted or not?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Mar 27, 2023
@kiburtse
Copy link
Contributor

@nicola-cab #6536 and #6531 might be relevant?

@nicola-cab
Copy link
Member

nicola-cab commented Apr 28, 2023

@nicola-cab #6536 and #6531 might be relevant?

I am not sure @kiburtse, this seems a bad accessor being returned to the user in the notification (however I cannot exclude that this is somehow being generated by the same bug, but in core 13.4 there was no support for multiprocess encryption... which again could be just exposing the underlying bug more easily, which is what I suspect)

@jedelbo
Copy link
Contributor

jedelbo commented Jun 21, 2023

The issue here is that a block is being freed twice. The issues that @kiburtse refers to has the same symptom, so there is definitely something fishy here. @markstratman it sounds like you are able to reproduce this issue. Would it be possible to share a minimal application that can sometimes reproduce this? (I am not a .Net developer, so I am not able to figure out if the code above is sufficient)

@jedelbo
Copy link
Contributor

jedelbo commented Jun 21, 2023

Another duplicate of this could be #6340

@jedelbo
Copy link
Contributor

jedelbo commented Jul 21, 2023

@markstratman I would still like to pursue this issue. So it you still have a more complete program, that triggers this problem and if you are willing to share that, it would be most helpful.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
O-Community Waiting-For-Reporter Waiting for more information from the reporter before we can proceed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants