realm-core icon indicating copy to clipboard operation
realm-core copied to clipboard

Crash within a write transaction while recreating the free list.

Open ripplek opened this issue 1 year ago • 16 comments

SDK and version

SDK : 'RealmSwift' Version: '10.37.0'

Observations

  • How frequent do the crash occur? It's a must for this user
  • Does it happen in production or during dev/test? Production
  • Can the crash be reproduced by you? No
  • Can you provide instructions for how we can reproduce it? No

Crash log / stacktrace


Incident Identifier: 9D63430A-B880-4A77-82E8-3E3BBC016D72
CrashReporter Key:   9b1cd65085feeb6e361d4308bbf26bbcd0eb13de
Hardware Model:      iPhone13,3
Process:             BGIM [407]
Path:                /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/BGIM
Identifier:          cc.sachsen.bgim.user.inhouse
Version:             2.5.8 (8)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           cc.sachsen.bgim.user.inhouse [444]

Date/Time:           2023-03-14 15:59:56.7220 +0800
Launch Time:         2023-03-14 15:59:54.5418 +0800
OS Version:          iPhone OS 16.3.1 (20D67)
Release Type:        User
Baseband Version:    3.40.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  3

Application Specific Information:
abort() called


Thread 0 name:   Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib        	       0x1d0b3cda8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1d0b4fa1c mach_msg2_internal + 80
2   libsystem_kernel.dylib        	       0x1d0b4fc5c mach_msg_overwrite + 388
3   libsystem_kernel.dylib        	       0x1d0b3d2ec mach_msg + 24
4   CoreFoundation                	       0x193099ac4 __CFRunLoopServiceMachPort + 160
5   CoreFoundation                	       0x19309ad08 __CFRunLoopRun + 1232
6   CoreFoundation                	       0x19309feb0 CFRunLoopRunSpecific + 612
7   GraphicsServices              	       0x1cd295368 GSEventRunModal + 164
8   UIKitCore                     	       0x195595668 -[UIApplication _run] + 888
9   UIKitCore                     	       0x1955952cc UIApplicationMain + 340
10  BGIM                          	       0x104145bfc main (in BGIM) (AppDelegate.swift:14) + 23548
11  dyld                          	       0x1b1998960 start + 2528

Thread 1 name:   Dispatch queue: nio.nioTransportServices.connectionchannel
Thread 1:
0   libswiftCore.dylib            	       0x18d1d27b8 swift_getTupleTypeMetadata + 528
1   libswiftCore.dylib            	       0x18d1d2610 swift_getTupleTypeMetadata + 104
2   libswiftCore.dylib            	       0x18d1d37c8 swift_getTupleTypeMetadata2 + 32
3   libswiftCore.dylib            	       0x18cf3f20c BinaryInteger._description(radix:uppercase:) + 124
4   BGIM                          	       0x10422dd1c FileLogger.log(level:message:metadata:file:function:line:) (in BGIM) (Logger.swift:143) + 974108
5   BGIM                          	       0x104237e20 specialized Sequence.forEach(_:) (in BGIM) (<compiler-generated>:0) + 1015328
6   BGIM                          	       0x10422f5f4 RollingFileLogger.log(level:message:metadata:file:function:line:) (in BGIM) (<compiler-generated>:0) + 980468
7   BGIM                          	       0x10422f65c protocol witness for LoggerProtocol.log(level:message:metadata:file:function:line:) in conformance RollingFileLogger (in BGIM) (<compiler-generated>:0) + 980572
8   BGIM                          	       0x10422f9fc CustomLogHandler.log(level:message:metadata:file:function:line:) (in BGIM) (<compiler-generated>:0) + 981500
9   Logging                       	       0x1074d9cfc MultiplexLogHandler.log(level:message:metadata:source:file:function:line:) + 344
10  XIMSDK                        	       0x10ab27938 Logger.warn(_:file:function:line:) + 1100
11  XIMSDK                        	       0x10ab271a8 Logger.info(_:file:function:line:) + 36
12  XIMSDK                        	       0x10ab255a4 LoggingClientInterceptor.receive(_:context:) + 516
13  GRPC                          	       0x106f60e38 ClientInterceptorPipeline._invokeReceive(_:onContextAtUncheckedIndex:) + 292
14  GRPC                          	       0x106f60ca4 ClientInterceptorPipeline.receive(_:) + 72
15  GRPC                          	       0x106f68fb0 ClientTransport._receiveFromChannel(message:) + 344
16  GRPC                          	       0x106f696dc specialized ClientTransport.channelRead(context:data:) + 176
17  NIOCore                       	       0x107a7a018 ChannelHandlerContext.invokeChannelRead(_:) + 68
18  NIOCore                       	       0x107a77988 ChannelHandlerContext.fireChannelRead(_:) + 40
19  GRPC                          	       0x106fa7ca8 GRPCClientChannelHandler.consumeBytes(from:context:) + 1356
20  GRPC                          	       0x106fa719c GRPCClientChannelHandler.readData(content:context:) + 904
21  GRPC                          	       0x106fa80e4 protocol witness for _ChannelInboundHandler.channelRead(context:data:) in conformance GRPCClientChannelHandler + 208
22  NIOCore                       	       0x107a7a018 ChannelHandlerContext.invokeChannelRead(_:) + 68
23  NIOCore                       	       0x107a79140 ChannelPipeline.fireChannelRead(_:) + 96
24  NIOHTTP2                      	       0x107ed08f4 HTTP2StreamChannel.deliverPendingReads() + 620
25  NIOHTTP2                      	       0x107ed16ec HTTP2StreamChannel.receiveStreamClosed(_:) + 124
26  NIOHTTP2                      	       0x107eda6bc HTTP2StreamMultiplexer.userInboundEventTriggered(context:event:) + 192
27  NIOCore                       	       0x107a7a180 ChannelHandlerContext.invokeUserInboundEventTriggered(_:) + 68
28  NIOCore                       	       0x107a77a24 ChannelHandlerContext.fireUserInboundEventTriggered(_:) + 40
29  GRPC                          	       0x106fb3f08 GRPCIdleHandler.userInboundEventTriggered(context:event:) + 604
30  NIOCore                       	       0x107a7a180 ChannelHandlerContext.invokeUserInboundEventTriggered(_:) + 68
31  NIOCore                       	       0x107a77a24 ChannelHandlerContext.fireUserInboundEventTriggered(_:) + 40
32  NIOHTTP2                      	       0x107ea8008 NIOHTTP2Handler.processPendingUserEvents(context:) + 408
33  NIOHTTP2                      	       0x107eaa0c4 NIOHTTP2Handler.processFrame(_:flowControlledLength:context:) + 2488
34  NIOHTTP2                      	       0x107ea7e28 NIOHTTP2Handler.channelRead(context:data:) + 200
35  NIOCore                       	       0x107a7a018 ChannelHandlerContext.invokeChannelRead(_:) + 68
36  NIOCore                       	       0x107a6f6c0 _ChannelInboundHandler.channelRead(context:data:) + 40
37  NIOCore                       	       0x107a7a018 ChannelHandlerContext.invokeChannelRead(_:) + 68
38  NIOCore                       	       0x107a77988 ChannelHandlerContext.fireChannelRead(_:) + 40
39  NIOSSL                        	       0x108225358 NIOSSLHandler.doFlushReadData(context:receiveBuffer:readOnEmptyBuffer:) + 152
40  NIOSSL                        	       0x108223c80 NIOSSLHandler.channelReadComplete(context:) + 92
41  NIOCore                       	       0x107a7a090 ChannelHandlerContext.invokeChannelReadComplete() + 60
42  NIOCore                       	       0x107a79278 ChannelPipeline.fireChannelRegistered() + 92
43  NIOTransportServices          	       0x1083464bc specialized NIOTSConnectionChannel.dataReceivedHandler(content:context:isComplete:error:) + 620
44  libswiftNetwork.dylib         	       0x1ae44a040 closure #1 in NWConnection.receiveMessage(completion:) + 168
45  libswiftNetwork.dylib         	       0x1ae449c90 thunk for @escaping @callee_guaranteed (@guaranteed OS_dispatch_data?, @guaranteed OS_nw_content_context?, @unowned Bool, @guaranteed OS_nw_error?) -> () + 108
46  libdispatch.dylib             	       0x19a650114 _dispatch_block_async_invoke2 + 148
47  libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
48  libdispatch.dylib             	       0x19a648640 _dispatch_lane_serial_drain + 672
49  libdispatch.dylib             	       0x19a6491c0 _dispatch_lane_invoke + 436
50  libdispatch.dylib             	       0x19a648518 _dispatch_lane_serial_drain + 376
51  libdispatch.dylib             	       0x19a6491c0 _dispatch_lane_invoke + 436
52  libdispatch.dylib             	       0x19a653e10 _dispatch_workloop_worker_thread + 652
53  libsystem_pthread.dylib       	       0x1e12a0df8 _pthread_wqthread + 288
54  libsystem_pthread.dylib       	       0x1e12a0b98 start_wqthread + 8

Thread 2 name:   Dispatch queue: harvesterQueue
Thread 2:
0   libsystem_kernel.dylib        	       0x1d0b3cd3c semaphore_timedwait_trap + 8
1   libdispatch.dylib             	       0x19a6415a0 _dispatch_sema4_timedwait + 64
2   libdispatch.dylib             	       0x19a641ba0 _dispatch_semaphore_wait_slow + 76
3   NewRelic                      	       0x1084715a0 -[NRMAHarvesterConnection send:] (in NewRelic) (NRMAHarvesterConnection.m:84) + 415136
4   NewRelic                      	       0x1084721f4 -[NRMAHarvesterConnection sendData:] (in NewRelic) (NRMAHarvesterConnection.m:0) + 418292
5   NewRelic                      	       0x108444db4 -[NRMAHarvester connected] (in NewRelic) (NRMAHarvester.mm:0) + 232884
6   NewRelic                      	       0x108446b58 -[NRMAHarvester execute] (in NewRelic) (NRMAHarvester.mm:557) + 240472
7   NewRelic                      	       0x10844637c -[NRMAHarvester transitionToConnected:] (in NewRelic) (NRMAHarvester.mm:488) + 238460
8   NewRelic                      	       0x108446b80 -[NRMAHarvester execute] (in NewRelic) (NRMAHarvester.mm:567) + 240512
9   NewRelic                      	       0x10841e534 __30+[NRMAHarvestController start]_block_invoke_2 (in NewRelic) (NRMAHarvestController.m:145) + 75060
10  libdispatch.dylib             	       0x19a63f460 _dispatch_call_block_and_release + 32
11  libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
12  libdispatch.dylib             	       0x19a648640 _dispatch_lane_serial_drain + 672
13  libdispatch.dylib             	       0x19a64918c _dispatch_lane_invoke + 384
14  libdispatch.dylib             	       0x19a653e10 _dispatch_workloop_worker_thread + 652
15  libsystem_pthread.dylib       	       0x1e12a0df8 _pthread_wqthread + 288
16  libsystem_pthread.dylib       	       0x1e12a0b98 start_wqthread + 8

Thread 3 Crashed:
0   libsystem_kernel.dylib        	       0x1d0b43674 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x1e12a71ac pthread_kill + 268
2   libsystem_c.dylib             	       0x19a6a4c8c abort + 180
3   Realm                         	       0x1089c8970 please_report_this_issue_in_github_realm_realm_core_v_13_6_0 + 12
4   Realm                         	       0x1089c8c58 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 260
5   Realm                         	       0x1089c8e54 realm::util::terminate_with_info(char const*, char const*, long, char const*, std::initializer_list<realm::util::Printable>&&) + 388
6   Realm                         	       0x108897c4c void realm::util::terminate_with_info<unsigned long const&, unsigned long long const&, unsigned long&, unsigned long&, unsigned long long&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(char const*, int, char const*, char const*, unsigned long const&, unsigned long long const&, unsigned long&, unsigned long&, unsigned long long&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) + 148
7   Realm                         	       0x1088974a0 realm::GroupWriter::recreate_freelist(unsigned long) + 2000
8   Realm                         	       0x1088957dc realm::GroupWriter::write_group() + 1124
9   Realm                         	       0x108877718 realm::DB::low_level_commit(unsigned long long, realm::Transaction&, bool) + 412
10  Realm                         	       0x108877480 realm::DB::do_commit(realm::Transaction&, bool) + 112
11  Realm                         	       0x1089a0084 realm::Transaction::commit_and_continue_as_read(bool) + 72
12  Realm                         	       0x108abf1a0 realm::_impl::RealmCoordinator::commit_write(realm::Realm&, bool) + 100
13  Realm                         	       0x108b558fc realm::Realm::commit_transaction() + 140
14  Realm                         	       0x1088083d8 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 248
15  RealmSwift                    	       0x10919b74c Realm.write<A>(withoutNotifying:_:) + 292
16  XIMSDK                        	       0x10abcdfe4 closure #1 in Storage.write(isSync:writeHandler:completionQueue:completion:) + 168
17  XIMSDK                        	       0x10abce16c closure #1 in closure #2 in Storage.write(isSync:writeHandler:completionQueue:completion:) + 20
18  XIMSDK                        	       0x10abb3f08 thunk for @callee_guaranteed () -> () + 20
19  XIMSDK                        	       0x10abb3f28 thunk for @escaping @callee_guaranteed () -> () + 20
20  libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
21  libdispatch.dylib             	       0x19a650574 _dispatch_lane_barrier_sync_invoke_and_complete + 56
22  XIMSDK                        	       0x10ab0a734 GroupDAO.updateGroupMember(groupID:account:type:) + 468
23  XIMSDK                        	       0x10aa00b40 ChatManager.fetchAllGroupInfo() + 324
24  BGIM                          	       0x10499fc49 closure #1 in ConversationsViewController.fetchGroupListIfNeeded(chatService:) (in BGIM) (ConversationsViewController.swift:581) + 8780873
25  BGIM                          	       0x1049a7ed5 partial apply for closure #1 in ConversationsViewController.fetchGroupListIfNeeded(chatService:) (in BGIM) (<compiler-generated>:0) + 8814293
26  BGIM                          	       0x1049304bd specialized thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) (in BGIM) (<compiler-generated>:0) + 8324285
27  BGIM                          	       0x104410bd9 partial apply for specialized thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out A) (in BGIM) + 1 + 2952153
28  libswift_Concurrency.dylib    	       0x19d4683a1 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1

Thread 4 name:  com.apple.uikit.eventfetch-thread
Thread 4:
0   libsystem_kernel.dylib        	       0x1d0b3cda8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1d0b4fa1c mach_msg2_internal + 80
2   libsystem_kernel.dylib        	       0x1d0b4fc5c mach_msg_overwrite + 388
3   libsystem_kernel.dylib        	       0x1d0b3d2ec mach_msg + 24
4   CoreFoundation                	       0x193099ac4 __CFRunLoopServiceMachPort + 160
5   CoreFoundation                	       0x19309ad08 __CFRunLoopRun + 1232
6   CoreFoundation                	       0x19309feb0 CFRunLoopRunSpecific + 612
7   Foundation                    	       0x18d3cc054 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8   Foundation                    	       0x18d3cbf3c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9   UIKitCore                     	       0x1956ca6a4 -[UIEventFetcher threadMain] + 436
10  Foundation                    	       0x18d3e5518 __NSThread__start__ + 716
11  libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
12  libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 5:
0   libsystem_pthread.dylib       	       0x1e12a0b90 start_wqthread + 0

Thread 6:
0   libsystem_pthread.dylib       	       0x1e12a0b90 start_wqthread + 0

Thread 7 name:   Dispatch queue: com.apple.network.connections
Thread 7:
0   libsystem_malloc.dylib        	       0x1a1518a44 small_free_list_add_ptr + 108
1   libsystem_malloc.dylib        	       0x1a1516230 small_malloc_from_free_list + 376
2   libsystem_malloc.dylib        	       0x1a1513e38 small_malloc_should_clear + 220
3   libsystem_malloc.dylib        	       0x1a15183b8 szone_malloc_should_clear + 120
4   CoreFoundation                	       0x1930a6284 _CFRuntimeCreateInstance + 756
5   Security                      	       0x19ae502a8 SecCertificateCreateWithBytes + 76
6   libboringssl.dylib            	       0x1bcbfd3e8 boringssl_helper_copy_certificates_from_CRYPTO_BUFFERs + 196
7   libboringssl.dylib            	       0x1bcbb752c boringssl_session_set_peer_verification_state_from_session + 160
8   libboringssl.dylib            	       0x1bcc19470 boringssl_context_certificate_verify_callback + 528
9   libboringssl.dylib            	       0x1bcc3adb8 bssl::ssl_verify_peer_cert(bssl::SSL_HANDSHAKE*) + 372
10  libboringssl.dylib            	       0x1bcbeac1c bssl::tls13_client_handshake(bssl::SSL_HANDSHAKE*) + 1376
11  libboringssl.dylib            	       0x1bcc30ab4 bssl::ssl_client_handshake(bssl::SSL_HANDSHAKE*) + 2552
12  libboringssl.dylib            	       0x1bcc3b670 bssl::ssl_run_handshake(bssl::SSL_HANDSHAKE*, bool*) + 376
13  libboringssl.dylib            	       0x1bcc068c4 SSL_do_handshake + 80
14  libboringssl.dylib            	       0x1bcbb81bc boringssl_session_handshake_continue + 108
15  libboringssl.dylib            	       0x1bcbc0fdc nw_protocol_boringssl_handshake_negotiate + 120
16  libboringssl.dylib            	       0x1bcbc14a0 nw_boringssl_read + 256
17  libboringssl.dylib            	       0x1bcbc2504 nw_protocol_boringssl_input_available + 348
18  libusrtcp.dylib               	       0x1f535d958 nw_protocol_tcp_wake_read + 532
19  libusrtcp.dylib               	       0x1f5364248 nw_protocol_tcp_input_flush + 104
20  Network                       	       0x193f44f4c nw_channel_add_input_frames(nw_channel*, nw_protocol*) + 10316
21  Network                       	       0x193f42610 nw_channel_update_input_source(nw_channel*, nw_protocol*, bool) + 328
22  Network                       	       0x193f4181c invocation function for block in nw_channel_create(nw_context*, unsigned char*, unsigned int, void*, unsigned int, bool, bool, bool*) + 72
23  libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
24  libdispatch.dylib             	       0x19a644418 _dispatch_continuation_pop + 504
25  libdispatch.dylib             	       0x19a657a58 _dispatch_source_invoke + 1588
26  libdispatch.dylib             	       0x19a64a4a4 _dispatch_workloop_invoke + 1780
27  libdispatch.dylib             	       0x19a653e10 _dispatch_workloop_worker_thread + 652
28  libsystem_pthread.dylib       	       0x1e12a0df8 _pthread_wqthread + 288
29  libsystem_pthread.dylib       	       0x1e12a0b98 start_wqthread + 8

Thread 8 name:  Realm notification listener
Thread 8:
0   libsystem_kernel.dylib        	       0x1d0b3e6e0 kevent + 8
1   Realm                         	       0x108aa5f34 realm::_impl::ExternalCommitHelper::listen() + 156
2   Realm                         	       0x108aa6090 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0> >(void*) + 52
3   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
4   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 9 name:  Realm notification listener
Thread 9:
0   libsystem_kernel.dylib        	       0x1d0b3e6e0 kevent + 8
1   Realm                         	       0x108aa5f34 realm::_impl::ExternalCommitHelper::listen() + 156
2   Realm                         	       0x108aa6090 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0> >(void*) + 52
3   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
4   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 10 name:  Realm notification listener
Thread 10:
0   libsystem_kernel.dylib        	       0x1d0b3e6e0 kevent + 8
1   Realm                         	       0x108aa5f34 realm::_impl::ExternalCommitHelper::listen() + 156
2   Realm                         	       0x108aa6090 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0> >(void*) + 52
3   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
4   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 11:
0   libsystem_kernel.dylib        	       0x1d0b3d67c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x1e12a806c _pthread_cond_wait + 1232
2   libc++.1.dylib                	       0x1a16ddacc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3   NewRelic                      	       0x108490dc0 NewRelic::WorkQueue::task_thread() (in NewRelic) + 272 + 544192
4   NewRelic                      	       0x108491344 std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::__execute() (in NewRelic) + 28 + 545604
5   NewRelic                      	       0x1084914e4 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >*> >(void*) (in NewRelic) + 72 + 546020
6   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
7   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 12:
0   libsystem_kernel.dylib        	       0x1d0b3d67c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x1e12a806c _pthread_cond_wait + 1232
2   libc++.1.dylib                	       0x1a16ddacc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3   NewRelic                      	       0x108490dc0 NewRelic::WorkQueue::task_thread() (in NewRelic) + 272 + 544192
4   NewRelic                      	       0x108491344 std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::__execute() (in NewRelic) + 28 + 545604
5   NewRelic                      	       0x1084914e4 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >*> >(void*) (in NewRelic) + 72 + 546020
6   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
7   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 13:
0   libsystem_kernel.dylib        	       0x1d0b3d67c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x1e12a806c _pthread_cond_wait + 1232
2   libc++.1.dylib                	       0x1a16ddacc std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 28
3   NewRelic                      	       0x108490dc0 NewRelic::WorkQueue::task_thread() (in NewRelic) + 272 + 544192
4   NewRelic                      	       0x108491344 std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::__execute() (in NewRelic) + 28 + 545604
5   NewRelic                      	       0x1084914e4 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<void (NewRelic::WorkQueue::*)(), NewRelic::WorkQueue*> >*> >(void*) (in NewRelic) + 72 + 546020
6   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
7   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 14 name:   Dispatch queue: cc.sks.ximsdk.sync.session.queue
Thread 14:
0   libsystem_kernel.dylib        	       0x1d0b3d67c __psynch_cvwait + 8
1   libsystem_pthread.dylib       	       0x1e12a806c _pthread_cond_wait + 1232
2   NIOConcurrencyHelpers         	       0x1079e57d0 ConditionLock.lock(whenValue:) + 224
3   XIMSDK                        	       0x10a9fa2cc specialized EventLoopFuture.wait(file:line:) + 984
4   XIMSDK                        	       0x10aa55710 closure #1 in ChatManager.syncSessions(after:completion:) + 804
5   XIMSDK                        	       0x10a9b1dc0 thunk for @escaping @callee_guaranteed () -> () + 28
6   libdispatch.dylib             	       0x19a63f460 _dispatch_call_block_and_release + 32
7   libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
8   libdispatch.dylib             	       0x19a648640 _dispatch_lane_serial_drain + 672
9   libdispatch.dylib             	       0x19a64918c _dispatch_lane_invoke + 384
10  libdispatch.dylib             	       0x19a653e10 _dispatch_workloop_worker_thread + 652
11  libsystem_pthread.dylib       	       0x1e12a0df8 _pthread_wqthread + 288
12  libsystem_pthread.dylib       	       0x1e12a0b98 start_wqthread + 8

Thread 15 name:   Dispatch queue: com.apple.root.default-qos
Thread 15:
0   libsystem_kernel.dylib        	       0x1d0b3cd24 semaphore_wait_trap + 8
1   libdispatch.dylib             	       0x19a641524 _dispatch_sema4_wait + 28
2   libdispatch.dylib             	       0x19a641bd8 _dispatch_semaphore_wait_slow + 132
3   CFNetwork                     	       0x19421e104 CFURLConnectionSendSynchronousRequest + 356
4   CFNetwork                     	       0x1942bbbb4 0x1941b3000 + 1084340
5   NewRelic                      	       0x10842fc2c __65+[NRMANSURLConnectionSupport poseImplementationBlockForSelector:]_block_invoke (in NewRelic) (NRMANSURLConnectionSupport.m:204) + 146476
6   Foundation                    	       0x18d3d9554 -[NSData(NSData) initWithContentsOfURL:] + 208
7   Foundation                    	       0x18d3d93ac +[NSData(NSData) dataWithContentsOfURL:] + 32
8   BGIM                          	       0x104fcbc34 -[JMapManager lastJudge] (in BGIM) (JMapManager.m:105) + 15252532
9   libdispatch.dylib             	       0x19a63f460 _dispatch_call_block_and_release + 32
10  libdispatch.dylib             	       0x19a640f88 _dispatch_client_callout + 20
11  libdispatch.dylib             	       0x19a644074 _dispatch_queue_override_invoke + 788
12  libdispatch.dylib             	       0x19a652a6c _dispatch_root_queue_drain + 396
13  libdispatch.dylib             	       0x19a653284 _dispatch_worker_thread2 + 164
14  libsystem_pthread.dylib       	       0x1e12a0dbc _pthread_wqthread + 228
15  libsystem_pthread.dylib       	       0x1e12a0b98 start_wqthread + 8

Thread 16:
0   libsystem_pthread.dylib       	       0x1e12a0b90 start_wqthread + 0

Thread 17 name:  Realm notification listener
Thread 17:
0   libsystem_kernel.dylib        	       0x1d0b3e6e0 kevent + 8
1   Realm                         	       0x108aa5f34 realm::_impl::ExternalCommitHelper::listen() + 156
2   Realm                         	       0x108aa6090 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&, realm::RealmConfig const&)::$_0> >(void*) + 52
3   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
4   libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8

Thread 18 name:  com.apple.NSURLConnectionLoader
Thread 18:
0   libsystem_kernel.dylib        	       0x1d0b3cda8 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1d0b4fa1c mach_msg2_internal + 80
2   libsystem_kernel.dylib        	       0x1d0b4fc5c mach_msg_overwrite + 388
3   libsystem_kernel.dylib        	       0x1d0b3d2ec mach_msg + 24
4   CoreFoundation                	       0x193099ac4 __CFRunLoopServiceMachPort + 160
5   CoreFoundation                	       0x19309ad08 __CFRunLoopRun + 1232
6   CoreFoundation                	       0x19309feb0 CFRunLoopRunSpecific + 612
7   CFNetwork                     	       0x19440aff0 0x1941b3000 + 2457584
8   Foundation                    	       0x18d3e5518 __NSThread__start__ + 716
9   libsystem_pthread.dylib       	       0x1e12a16cc _pthread_start + 148
10  libsystem_pthread.dylib       	       0x1e12a0ba4 thread_start + 8


Thread 3 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0cc11d6274d725c5   x9: 0x0cc11d631f32d5c5  x10: 0x0000000000000000  x11: 0x000000000000002b
   x12: 0x000000000000002b  x13: 0x0000000110000000  x14: 0x00000000000007fb  x15: 0x000000008781a80b
   x16: 0x0000000000000148  x17: 0x000000016be5f000  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x0000000000002203  x21: 0x000000016be5f0e0  x22: 0x0000000108c7de13  x23: 0x000000016be5dd08
   x24: 0x000000016be5dd08  x25: 0x000000016be5dd08  x26: 0x0000000108c7d836  x27: 0x0000000108cbdd38
   x28: 0x0000000108cbdf40   fp: 0x000000016be5dc50   lr: 0x00000001e12a71ac
    sp: 0x000000016be5dc30   pc: 0x00000001d0b43674 cpsr: 0x40001000
   far: 0x00000001266dc02c  esr: 0x56000080  Address size fault

Binary Images:
       0x1d0b3c000 -        0x1d0b73feb libsystem_kernel.dylib arm64e  <c76e6bed463530c68f19fb829bbe1ae1> /usr/lib/system/libsystem_kernel.dylib
       0x19301f000 -        0x193404fff CoreFoundation arm64e  <42ccfc7bff323d258f01ccb2ad843a8b> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
       0x1cd294000 -        0x1cd29cfff GraphicsServices arm64e  <85419099269b336d86b40d52d0ff6923> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
       0x1951f4000 -        0x1969e7fff UIKitCore arm64e  <cf21ad9cefbf3961a7c054bd30cefea9> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
       0x104140000 -        0x10581ffff BGIM arm64  <d1d5a03e504e323fad702f372ec6d597> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/BGIM
       0x1b1983000 -        0x1b1a06093 dyld arm64e  <4b042f280d1430eca1de3dbb10866ad7> /usr/lib/dyld
       0x18cdee000 -        0x18d356fff libswiftCore.dylib arm64e  <56c020fc03693775b947148f388a65b3> /usr/lib/swift/libswiftCore.dylib
       0x1074d0000 -        0x1074e3fff Logging arm64  <39dd8a97c517342ab66b2ad64f76d203> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/Logging.framework/Logging
       0x10a99c000 -        0x10ad73fff XIMSDK arm64  <3250ea22745a3911a5e6f2f18f5867d2> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/XIMSDK.framework/XIMSDK
       0x106f3c000 -        0x107033fff GRPC arm64  <70c9c745e0973a08a23a078d8209288c> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/GRPC.framework/GRPC
       0x107a54000 -        0x107ac3fff NIOCore arm64  <4721e27c256c300cb475a7c165e71ead> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NIOCore.framework/NIOCore
       0x107e70000 -        0x107f0bfff NIOHTTP2 arm64  <57e4f0d02c403d30bc112e7be047f115> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NIOHTTP2.framework/NIOHTTP2
       0x108218000 -        0x108253fff NIOSSL arm64  <8a671064744839ee87617ae96b5dc553> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NIOSSL.framework/NIOSSL
       0x108334000 -        0x108367fff NIOTransportServices arm64  <27194177e4dd3242891a4e58a08c52ce> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NIOTransportServices.framework/NIOTransportServices
       0x1ae432000 -        0x1ae4b1ff6 libswiftNetwork.dylib arm64e  <72b8a64c7fb83f779d3d1464f376773d> /usr/lib/swift/libswiftNetwork.dylib
       0x19a63d000 -        0x19a683fff libdispatch.dylib arm64e  <ded4d0a5142032ae83a6c31d938a1c9a> /usr/lib/system/libdispatch.dylib
       0x1e12a0000 -        0x1e12abfff libsystem_pthread.dylib arm64e  <45ac734e66493ee2a0963fd66441ab78> /usr/lib/system/libsystem_pthread.dylib
       0x10840c000 -        0x1084f3fff NewRelic arm64  <98a40762e4e33b49b5e11ac8bc77509f> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NewRelic.framework/NewRelic
       0x19a684000 -        0x19a703ff7 libsystem_c.dylib arm64e  <3cd8c9e025fd3b29850774cdffe7f16c> /usr/lib/system/libsystem_c.dylib
       0x1086e0000 -        0x108cb7fff Realm arm64  <49a67d3ddc313599b69c554789c60d59> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/Realm.framework/Realm
       0x109128000 -        0x10920bfff RealmSwift arm64  <75935675f02b3764a69397534ad1cce8> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/RealmSwift.framework/RealmSwift
       0x19d420000 -        0x19d47aff7 libswift_Concurrency.dylib arm64e  <28ca7ea72ba53ae991706f17dd614ee1> /usr/lib/swift/libswift_Concurrency.dylib
       0x18d38a000 -        0x18dcd3fff Foundation arm64e  <e5f615c7cc5e3656860041c767812a35> /System/Library/Frameworks/Foundation.framework/Foundation
       0x1a1512000 -        0x1a1535ffb libsystem_malloc.dylib arm64e  <81ce80b167ce333c9a2da1af0a729172> /usr/lib/system/libsystem_malloc.dylib
       0x19ae38000 -        0x19afc6fff Security arm64e  <9f07ab2003753be784032a58c116f87b> /System/Library/Frameworks/Security.framework/Security
       0x1bcbb3000 -        0x1bcc74fff libboringssl.dylib arm64e  <0e1fd57cf0103d8e95678e8a8efa9f2f> /usr/lib/libboringssl.dylib
       0x1f5340000 -        0x1f53abffe libusrtcp.dylib arm64e  <c552a96217ce3ad5946fd162df24046f> /usr/lib/libusrtcp.dylib
       0x193405000 -        0x1941b2fff Network arm64e  <66645d9c43363a4d8060866f18c64bd2> /System/Library/Frameworks/Network.framework/Network
       0x1a16d1000 -        0x1a1737ff3 libc++.1.dylib arm64e  <fd773d8112ea3339a780dc6e24fd6026> /usr/lib/libc++.1.dylib
       0x1079dc000 -        0x1079ebfff NIOConcurrencyHelpers arm64  <9c1f81f7e8613616b45d2fc4d87f3704> /private/var/containers/Bundle/Application/5AD3D543-9E8A-4F5B-AFBF-8C9D645B82E1/BGIM.app/Frameworks/NIOConcurrencyHelpers.framework/NIOConcurrencyHelpers
       0x1941b3000 -        0x19457cfff CFNetwork arm64e  <7f3313c9143533338c82dc961429d0b3> /System/Library/Frameworks/CFNetwork.framework/CFNetwork

EOF


Steps & Code to Reproduce

func updateGroupMember(groupID: String, account: String, type: GroupMemberType) {
    storage.write { realm in
        guard let member = realm.objects(GroupMemberObject.self).filter("groupID == %@ AND account == %@", groupID, account).first else {
            return
        }
        member.type = type
    }
    
}

// MARK: - Realm Setup

extension Storage {
    private var storageFolder: URL {
        let path = FileManager.documentURL.appendingPathComponent("XIMSDK/\(uid)", isDirectory: true)
        return path
    }

    private var realmUrl: URL {
        setup()
        return storageFolder.appendingPathComponent(type.realmFileName, isDirectory: false)
    }

    private var realmConfig: Realm.Configuration {
        var config = Realm.Configuration()
        config.objectTypes = type.managedObjectTypes
        config.schemaVersion = GlobalConstant.realmVersion
        config.fileURL = realmUrl
        config.deleteRealmIfMigrationNeeded = false
        config.shouldCompactOnLaunch = { totalBytes, usedBytes in
            // totalBytes refers to the size of the file on disk in bytes (data + free space)
            // usedBytes refers to the number of bytes used by data in the file
            // Compact if the file is over 100MB in size and less than 50% 'used'
            let oneHundredMB = 100 * 1024 * 1024
            return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5
        }
        return config
    }

    private var realm: Realm {
        do {
            Realm.Configuration.defaultConfiguration = realmConfig
            let realm = try Realm(configuration: realmConfig)
            return realm
        } catch {
            log.error(error, realmConfig)
            fatalError("create realm failed: \(error)")
        }
    }

    private func setup() {
        guard !FileManager.default.fileExists(atPath: storageFolder.path) else {
            return
        }

        do {
            #if os(macOS)
                let attributes: [FileAttributeKey: Any] = [:]
            #elseif os(iOS)
                let attributes: [FileAttributeKey: Any] = [FileAttributeKey.protectionKey: FileProtectionType.none]
            #endif
            try FileManager.default.createDirectory(at: storageFolder,
                                                    withIntermediateDirectories: true,
                                                    attributes: attributes)
        } catch {
            log.error("create store folder failed: \(error)")
        }
    }

    func refresh() {
        realm.refresh()
    }

    func destroy() {
        do {
            try realm.write {
                realm.deleteAll()
            }
            try FileManager.default.removeItem(at: realmUrl)
        } catch {
            log.error("remove realm file failed: \(error)")
        }
    }
}

enum Sorter {
    case ascending(String)
    case descending(String)

    var keyPath: String {
        switch self {
        case let .ascending(keyPath):
            return keyPath
        case let .descending(keyPath):
            return keyPath
        }
    }

    var ascending: Bool {
        switch self {
        case .ascending:
            return true
        case .descending:
            return false
        }
    }
}

extension Sorter: CustomStringConvertible {
    var description: String {
        switch self {
        case let .ascending(keyPath):
            return "ascending(\(keyPath))"
        case let .descending(keyPath):
            return "descending(\(keyPath))"
        }
    }
}

// MARK: - CURD

extension Storage {
    typealias WriteHandler = (Realm) -> Void
    
    typealias CompletionHandler = (Result<Realm, Error>) -> Void
    
    func write(isSync: Bool = true, writeHandler: @escaping WriteHandler, completionQueue: DispatchQueue = .main, completion: CompletionHandler? = nil) {
        let operation: () -> Void = {
            
            let realm = self.realm
            let realmConfig = self.realmConfig
            
            do {
                try realm.write {
                    writeHandler(realm)
                }
                if completion != nil {
                    completion?(.success(realm))
                }
            } catch let error {
                log.error("write to database failed. error: \(error)")
                if completion != nil {
                    completion?(.failure(error))
                }
            }
        }
        
        autoreleasepool { () -> Void in
            if isSync {
                storageQueue.sync {
                    operation()
                }
            } else {
                storageQueue.async {
                    operation()
                }
            }
        }
    }
    
    func query<T: Object>(_ type: T.Type = T.self, filter: NSPredicate? = nil, sorters: [Sorter] = []) -> Results<T> {
        var results = realm.objects(type)

        if let filter = filter {
            results = results.filter(filter)
        }
        if !sorters.isEmpty {
            results = results.sorted(by: sorters.map { RealmSwift.SortDescriptor(keyPath: $0.keyPath, ascending: $0.ascending) })
        }

        return results
    }
    
    func query<Element: Object, KeyType>(ofType type: Element.Type, forPrimaryKey key: KeyType) -> Element? {
        return realm.object(ofType: type, forPrimaryKey: key)
    }
}

ripplek avatar Mar 14 '23 09:03 ripplek