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

realm::util::File::barrier() #8664

Open
ppave opened this issue Aug 7, 2024 · 9 comments
Open

realm::util::File::barrier() #8664

ppave opened this issue Aug 7, 2024 · 9 comments

Comments

@ppave
Copy link

ppave commented Aug 7, 2024

How frequently does the bug occur?

Often, many new users affected

Description

at calling try realm.write {

Stacktrace & log output

2   RealmSwift                    	0x00000001052cc5c0 realm::util::File::barrier() + 28 (file.cpp:1130)
3   RealmSwift                    	0x0000000105058084 realm::GroupCommitter::commit(unsigned long) + 324 (group_writer.cpp:1411)
4   RealmSwift                    	0x0000000105034aa4 realm::DB::low_level_commit(unsigned long long, realm::Transaction&, bool) + 664 (db.cpp:2580)
5   RealmSwift                    	0x0000000105034770 realm::DB::do_commit(realm::Transaction&, bool) + 228 (db.cpp:2488)
6   RealmSwift                    	0x00000001052b3564 realm::Transaction::commit_and_continue_as_read(bool) + 68 (transaction.cpp:272)
7   RealmSwift                    	0x00000001050e1e08 realm::_impl::RealmCoordinator::commit_write(realm::Realm&, bool) + 100 (realm_coordinator.cpp:778)
8   RealmSwift                    	0x0000000105123994 realm::Realm::commit_transaction() + 108 (shared_realm.cpp:1072)
9   RealmSwift                    	0x0000000105403ddc -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 248 (RLMRealm.mm:631)
10  RealmSwift                    	0x0000000104f51e70 Realm.commitWrite(withoutNotifying:) + 116 (Realm.swift:332)
11  RealmSwift                    	0x0000000104f51d8c Realm.write<A>(withoutNotifying:_:) + 224 (Realm.swift:270)

and

0   libsystem_kernel.dylib        	0x00000001e2d66cd8 __msync + 8 (:-1)
1   RealmSwift                    	0x0000000103224944 realm::util::msync(int, void*, unsigned long) + 148 (file_mapper.cpp:912)
2   RealmSwift                    	0x0000000102fa8074 realm::util::File::Map<char>::sync() + 8 (file.hpp:1178)
3   RealmSwift                    	0x0000000102fa8074 realm::WriteWindowMgr::MapWindow::sync() + 16 (group_writer.cpp:187)
4   RealmSwift                    	0x0000000102fa8074 realm::WriteWindowMgr::sync_all_mappings() + 76 (group_writer.cpp:340)
5   RealmSwift                    	0x0000000102f88a74 realm::DB::low_level_commit(unsigned long long, realm::Transaction&, bool) + 616 (db.cpp:2576)
6   RealmSwift                    	0x0000000102f88770 realm::DB::do_commit(realm::Transaction&, bool) + 228 (db.cpp:2488)
7   RealmSwift                    	0x0000000103207564 realm::Transaction::commit_and_continue_as_read(bool) + 68 (transaction.cpp:272)
8   RealmSwift                    	0x0000000103035e08 realm::_impl::RealmCoordinator::commit_write(realm::Realm&, bool) + 100 (realm_coordinator.cpp:778)
9   RealmSwift                    	0x0000000103077994 realm::Realm::commit_transaction() + 108 (shared_realm.cpp:1072)
10  RealmSwift                    	0x0000000103357ddc -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 248 (RLMRealm.mm:631)
11  RealmSwift                    	0x0000000102ea5e70 Realm.commitWrite(withoutNotifying:) + 116 (Realm.swift:332)
12  RealmSwift                    	0x0000000102ea5d8c Realm.write<A>(withoutNotifying:_:) + 224 (Realm.swift:270)


### Can you reproduce the bug?

No

### Reproduction Steps

_No response_

### Version

10.52.0

### What Atlas Services are you using?

Local Database only

### Are you using encryption?

No

### Platform OS and version(s)

different versions of iOS

### Build environment

Xcode 15
SPM
Copy link

sync-by-unito bot commented Aug 7, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2419

@nirinchev
Copy link
Member

This bug report is overly generic and without repro steps or more information there's nothing we can do.

@nirinchev nirinchev added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Aug 7, 2024
@ppave
Copy link
Author

ppave commented Aug 7, 2024

It happens when the app starts, most likely it's the first call to the Realm local db.
There is a chance that this happens when a user opens the new app version with the new db schema.

Would be good if you could tell me based on the above logs might it be related to the db migration or not, it may help me with providing you more details.

@nirinchev

@github-actions github-actions bot removed the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Aug 7, 2024
@nirinchev
Copy link
Member

No, based on the stacktrace, this is happening when you explicitly call .write, which means any migration must have completed at this point and the realm must have been opened successfully.

The error seems to be occurring when the transaction is committed and msync is invoked for the file to write the data on disk. Without the underlying error that's causing msync to fail, it's not obvious to me how we could go about and try and repro this. One thing though, in your ticket you're saying that the issue occurs always yet you're unable to reproduce it - that's somewhat inconsistent - can you clarify which one is it.

@ppave
Copy link
Author

ppave commented Aug 7, 2024

Thank you for the details.
Let me collect more info. The problem with these crashes is that for some reason they don't appear in Firebase and the update is incremental, so need more time to see the full picture, but need to make actions right now.
Will keep it updated.

@Jaycyn
Copy link

Jaycyn commented Aug 7, 2024

It would likely help if we could see a small code example of the code that crashes - the code one-liner in the report won't cause that crash by itself. For example, what is your realm configuration? Is that code being called in an actor? background? something else? SwiftUI? Swift? Is it crashing ON that line or within the closure?

@ppave
Copy link
Author

ppave commented Aug 7, 2024

UIKit, Main thread, not background, no Swift Concurrency used
Crashing on this line
Screenshot 2024-08-07 at 23 29 04

Configuration is quite simple:

 private static var realmConfiguration: Realm.Configuration = {
        var id = "xxxxxx"
        var containerGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: id)
        guard let containerGroupURL else {
            fatalError("Could not resolve a valid URL for Realm database.")
        }
        let config = Realm.Configuration(fileURL: containerGroupURL.appendingPathComponent("default.realm"),
                                         deleteRealmIfMigrationNeeded: true)
        return config
    }()
    
    private init() {
        assert(Thread.isMainThread)
        let realm = try! Realm(configuration: Self.realmConfiguration)
        self.realm = realm
    }

My current hypothesis is that there are conflicting write operations in the app group folder that may delete some realm files. But I don't understand why in this case these errors are floating and we can not reproduce them on our side.
Checking this now.

@ppave
Copy link
Author

ppave commented Aug 11, 2024

Updated from 10.52.0 to 10.52.2 + deleted all code that may conflict with the Realm files in the file system.
But these issues still happen, especially realm::util::File::barrier()

My next step will be to revert back to the 10.43.0 that was running good for us.
Maybe that's the case, but of course we did also other changes.
But would be good to get any ideas of what can cause the above issues.

  1. May it be related to the fact that Realm write is called from the RxSwift chain?
  2. Also, will migration to the previuos Realm version (in my case from 10.52.2 back to 10.43.0) bring any issues?

Please find more details of the crash.

iOS 17.6, iOS 17.5, iOS 17.4.. devices

Screenshot 2024-08-11 at 09 35 46

@SystemKeeper
Copy link

I have seen this as well, but for me it always was a 0xdead10cc crash:

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: RUNNINGBOARD 0xdead10cc 

Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000001da7f5958 __fcntl + 8 (:-1)
1   libsystem_kernel.dylib        	0x00000001da7f5924 fcntl + 88 (fcntl-base.c:84)
2   Realm                         	0x00000001063e8654 realm::util::File::barrier() + 28 (:-1)
3   Realm                         	0x00000001062b9ef4 realm::DB::low_level_commit(unsigned long long, realm::Transaction&, bool) + 672
4   Realm                         	0x00000001062b9bb4 realm::DB::do_commit(realm::Transaction&, bool) + 252
5   Realm                         	0x00000001063c590c realm::Transaction::commit_and_continue_as_read(bool) + 72 (:-1)
6   Realm                         	0x00000001064e7850 realm::_impl::RealmCoordinator::commit_write(realm::Realm&, bool) + 100 (:-1)
7   Realm                         	0x000000010653a1c0 realm::Realm::commit_transaction() + 140 (:-1)
8   Realm                         	0x00000001066aaea8 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 248 (:-1)
9   Realm                         	0x00000001066aaff8 -[RLMRealm transactionWithoutNotifying:block:error:] + 104
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants