Сбой Realm при разрешении ThreadSafeReference - PullRequest
0 голосов
/ 08 мая 2020

При попытке вернуть результаты из отдельного потока мое приложение просто перестает работать и закрывается, при наличии доступной информации я смог написать этот код

public async override Task<IQueryable<Entry>> FindAsync(string inputText)
{
    var resultingEntries = await Task.Run(() =>
    {
        // The heavy stuff starts here, in anew thread.
        using (var realm = Realm.GetInstance(DbConfig))
        {
            // All data
            var bgHaystack = realm.All<Entry>();

            // Because realm doesn't support some of the LINQ operations on not stored fields (Content)
            // the set of entries is converted to a IEnumerable.
            IEnumerable<Entry> subset = bgHaystack;

            // This is where the search gets actually done
            subset = subset.Where(entry => entry.Content.ToLower().StartsWith(inputText));

            // Extracts ids
            var foundEntryIds = ExtractIdsFromEntries(subset);

            // Select entries
            var foundEntries = FindingManyMatches(bgHaystack, foundEntryIds.ToArray());

            return ThreadSafeReference.Create(foundEntries);
        }
    });

    var results = Realm.GetInstance(DbConfig).ResolveReference(resultingEntries);
    return results;
}

И все работает нормально, кроме для предпоследней строки, где я хочу получить полученный объект, знаете ли вы, что здесь не так и как решить эту проблему?

Трассировка стека:

Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

No native Android stacktrace (see debuggerd output).

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x7cdcb67c70):0x7cdcb67c60  c0 03 5f d6 c8 02 80 52 e0 03 08 2a c0 03 5f d6  .._....R...*.._.
0x7cdcb67c70  08 00 40 79 09 3d 0e 53 08 3d 00 12 69 01 00 35  ..@y.=.S.=..i..5
0x7cdcb67c80  09 01 13 12 2a 01 00 32 0b fc 5f 48 7f 21 29 6b  ....*..2.._H.!)k
0x7cdcb67c90  a1 00 00 54 0a 7c 0b 48 8b ff ff 35 e0 03 1f 2a  ...T.|.H...5...*

================================================

05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_object_reference'.=================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at NativeMethods:resolve_query_reference <0x00007>
      at Realms.SharedRealmHandle:ResolveReference <0x00243>
      at Realms.Realm:ResolveReference <0x0008f>
      at <FindAsync>d__9:MoveNext <0x0062f>
      at MoveNextRunner:InvokeMoveNext <0x000f3>
      at System.Threading.ExecutionContext:RunInternal <0x003af>
      at System.Threading.ExecutionContext:Run <0x0006b>
      at MoveNextRunner:Run <0x00193>
      at <>c:<.cctor>b__7_0 <0x0009b>
      at <>c__DisplayClass2_0:<Post>b__0 <0x00093>
      at RunnableImplementor:Run <0x000bb>
      at Java.Lang.IRunnableInvoker:n_Run <0x000c3>
      at Android.Runtime.DynamicMethodNameCounter:20 <0x000af>
      at Android.Runtime.DynamicMethodNameCounter:20 <0x000e3>
=================================================================

05-08 23:09:47.037 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.037 D/Mono    (25933): Searching for 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): Probing 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_list_reference'.
05-08 23:09:47.037 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.037 D/Mono    (25933): Searching for 'shared_realm_resolve_query_reference'.
05-08 23:09:47.037 D/Mono    (25933): Probing 'shared_realm_resolve_query_reference'.
05-08 23:09:47.037 D/Mono    (25933): Found as 'shared_realm_resolve_query_reference'.
05-08 23:09:47.040 F/libc    (25933): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x188 in tid 25933 (panyname.dosham), pid 25933 (panyname.dosham)
05-08 23:09:47.061 D/Mono    (25933): DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so').
05-08 23:09:47.062 D/Mono    (25933): Searching for 'query_destroy'.
05-08 23:09:47.062 D/Mono    (25933): Probing 'query_destroy'.
05-08 23:09:47.062 D/Mono    (25933): Found as 'query_destroy'.
05-08 23:09:47.259 I/panyname.dosha(25933): ProcessProfilingInfo new_methods=0 is saved saved_to_disk=0 resolve_classes_delay=8000

1 Ответ

0 голосов
/ 08 мая 2020

Похоже, это ошибка, удаление

using (var realm = Realm.GetInstance(DbConfig))

решило проблему, т.е.

            var resultingEntries = await Task.Run(() =>
            {
                var allEntries = Realm.GetInstance(DbConfig).All<Entry>();

                // Because realm doesn't support some of the LINQ operations on not stored fields (Content)
                // the set of entries is converted to a IEnumerable.
                IEnumerable<Entry> subset = allEntries;

                // This is where the search gets actually done
                subset = subset.Where(entry => entry.Content.ToLower().StartsWith(inputText));

                // Extracts ids
                var foundEntryIds = ExtractIdsFromEntries(subset);

                // Select entries
                var foundEntries = FindingManyMatches(allEntries, foundEntryIds.ToArray());
                var foundEntriesCount = foundEntries.Count();

                return ThreadSafeReference.Create(foundEntries);
            });

            var results = Realm.GetInstance(DbConfig).ResolveReference(resultingEntries);
            return results;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...