Closed dsanghan closed 5 years ago
If it only happens while the app is in the background it's probably related to NSFileProtection, although I've never heard of file protection causing problems in this specific way. If you can reproduce the problem yourself, you could try disabling file protection just to see if it is related.
The actual error that's happening here is that once we're at the writing to the file step of committing a write transaction, we map 1 MB writeable windows for each of the parts of the file that we need to write to (normally the Realm is mapped as read-only). This normally can only fail if the process is out of address space (almost certainly not the problem here) or if we don't have permission to write to the file. If you use commitWriteTransactionWithError:
to get an NSError
object when the write fails it should have the original error code that says why exactly mmap()
failed.
Hi! 5% of users have same problems. We using RealmSwift and have tried to disable encryption and/or shouldCompactOnLaunch as we saw it in others issues, but it does not work. I guess this bug reproduced only in release configuration, because I've never seen it during development.
My config code:
var config = Realm.Configuration()
config.schemaVersion = 40
config.shouldCompactOnLaunch = { totalBytes, usedBytes in
let oneHundredMB = 100 * 1_024 * 1_024
return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5
}
config.migrationBlock = { migration, oldSchemaVersion in
if oldSchemaVersion < 34 {
self.foo(migration: migration)
}
}
Realm.Configuration.defaultConfiguration = config
One of my crashlogs:
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 2415919104 offset: 0" UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 2415919104 offset: 0, Error Code=9}: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/core/ErrorType.swift, line 184 2019-01-17 17:12:47.831878+0300 Express[44069:14842020] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=9 "mmap() failed: Cannot allocate memory size: 2415919104 offset: 0" UserInfo={NSLocalizedDescription=mmap() failed: Cannot allocate memory size: 2415919104 offset: 0, Error Code=9}: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/core/ErrorType.swift, line 184
This is fresh install, realm file should not be this size, 10mb max.
@tgoyne You were right, the address space was being consumed by another library in specific cases when the iOS app was fetching in the background. I've opened an issue in that library. Thanks!
Hey - looks like you forgot to add a T:* label - could you please add one?
hi guys, issue still exist but ticket was closed. Tested in latest version of realmswift,
Version updated, Installing RealmSwift 3.17.0 (was 3.16.2)
Tested device: iPhone 6s
Available free storage, 40GB
Error, mmap() failed: Cannot allocate memory size: 2415919104 offset: 0
@dsanghan Could you post the library you saw this issue in?
I'm seeing the same crash. A lot. Any updates here?
@kduellman I was seeing because of https://github.com/MailCore/mailcore2 - the threads being created for IDLE connections were leaking in the background, making the app run out of address space. Once that was resolved, we stopped seeing this realm crash completely.
I'm seeing this same crash consistently when leaving the app running for more than ~5 minutes. @dsanghan - how were you able to diagnose that third-party leak?
Goals
Realm works without crashing in all scenarios
Expected Results
Realm works without crashing
Actual Results
Realm crashes when transactions are committed in the background or when coming out of background.
Info
I've read the other stackoverflow posts as well as the realm issues that suggest using shouldCompactOnLaunch. I've implemented it in our latest release, but still see this crash.
I've verified that the database is ~ 5MB in size.
This crash only happens when the app is either in background or coming out of background.
In every crash log, the allocation failure is for the same size (1048576). I've confirmed the DB is not growing arbitrarily large.
Code Sample
Version of Realm and Tooling