Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 55672832 offset: 335544320"
SDK and version
SDK : realm-swift Version: 10.28.0
Observations
- How frequently does the crash occur?
The crash happens 4-5 times for each of our users per day (the app is used throughout the day)
- Does it happen in production or during dev/test?
We cannot reproduce it deterministically on a dev environment, although it happens during development occasionally too.
- Can the crash be reproduced by you?
Sometimes, but it's random, see above.
- Can you provide instructions for how we can reproduce it?
It is random crash.
Crash log / stacktrace
Fatal Exception: RLMException
0 CoreFoundation 0x99d78 __exceptionPreprocess
1 libobjc.A.dylib 0x16734 objc_exception_throw
2 CarmaGo 0x5fa9a4 -[RLMRealm refresh] + 918 (RLMRealm.mm:918)
3 CarmaGo 0x696f3c Realm.refresh() + 903 (Realm.swift:903)
4 CarmaGo 0x130068 closure #1 in MapViewModel.setupResultPublisher() + 272 (MapViewModel.swift:272)
5 Combine 0xb4b0 Subscribers.Sink.receive(_:)
6 Combine 0xada8 protocol witness for Subscriber.receive(_:) in conformance Subscribers.Sink<A, B>
7 Combine 0x129fc closure #1 in Publishers.ReceiveOn.Inner.receive(_:)
8 libswiftDispatch.dylib 0x1c04 thunk for @escaping @callee_guaranteed () -> ()
9 libdispatch.dylib 0x1e68 _dispatch_call_block_and_release
10 libdispatch.dylib 0x3a2c _dispatch_client_callout
11 libdispatch.dylib 0xb124 _dispatch_lane_serial_drain
12 libdispatch.dylib 0xbc80 _dispatch_lane_invoke
13 libdispatch.dylib 0x16500 _dispatch_workloop_worker_thread
14 libsystem_pthread.dylib 0x10bc _pthread_wqthread
15 libsystem_pthread.dylib 0xe5c start_wqthread
Steps & Code to Reproduce
(For a detailed history of the issue please take a look here: https://github.com/realm/realm-swift/issues/7814)
The crash is random. We had many incidents a month ago and we found out that the main problem was that we were creating a Combine collectionPublisher and then we were adding a subscribe(on:) publisher to kick it off on a background thread. This ultimately led to an enormous count of WeakRealmNotifier.notify() instances to be created, which apparently (though we are not 100% sure) led to a mmap()exception.
However the problem still persists.
Our app stores and modifies objects really quickly (we get live updates from the sensors and we need to provide immediate feedback to the user and store the state at the same time), and after some thousand objects (which probably translate to tens of thousands transactions) we still get the same error. However the object count of WeakRealmNotifier.notify() and the app size stays within normal levels (no more than 2-3 MB, the most we've seen is 5MB). The open Realms are around 3 each time and we have around 10 stored instances of collections and objects that are accessed through the main thread.
It's been almost a month since we first mentioned this issue on the realm-swift repo, and it still affects almost 100% of our users, although more sparingly than before. However, it is still a very bad UX to have the app crash two or three times within 6-7 hours of use because of this Realm bug.
Is it possible that you take a look and help us figure it out? It seems to be a common issue across many Realm versions, albeit for different reasons each time.
➤ Daniel Tabacaru commented:
[[email protected]], [[email protected]]: Could any of you take a look at this? (it looks like something we've seen on iOS before and we're attempting to fix it with the block manager)
Potential mitigation/fix in progress: https://github.com/realm/realm-core/pull/5645
➤ finnschiermer commented:
Assumed fixed per comment above (and the silence following it).