realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.34k stars 2.15k forks source link

Crashes when trying to get a value #3541

Closed GZaccaroni closed 8 years ago

GZaccaroni commented 8 years ago

Goals

What do you want to achieve? Getting a value from a database, 30% of my users experience that error

Expected Results

What did you expected to happen? Get a row from a database

Actual Results

What did happened instead?
e.g. the stack trace of a crash

Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x100ab7e80 specialized _assertionFailed(StaticString, String, StaticString, UInt) -> () (__hidden#4861_)
1  libswiftCore.dylib             0x1009d03f0 swift_errorInMain (__hidden#7062_:59)
2  Registro Elettronico           0x1000a65a8 static Database.((realm in _1F817CD68B79AE16AC37F0F7B67FF18B)).(variable initialization expression).(closure #1) (Realm.swift:88)
3  Registro Elettronico           0x10009a8d0 globalinit_33_1F817CD68B79AE16AC37F0F7B67FF18B_func0 (Realm.swift:99)
4  libdispatch.dylib              0x19a0956a8 _dispatch_client_callout + 16
5  libdispatch.dylib              0x19a0964ec dispatch_once_f + 80
6  Registro Elettronico           0x1000a388c specialized Database.estraiValoreImpostazione(String) -> String (Realm.swift:49)
7  Registro Elettronico           0x1000a2160 Database.estraiValoreImpostazione(String) -> String (Realm.swift:492)
8  Registro Elettronico           0x10004aae0 specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift:28)
9  Registro Elettronico           0x100049b88 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift)
10 UIKit                          0x18a2cd324 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400
11 UIKit                          0x18a4fbacc -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904
12 UIKit                          0x18a4ffe0c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1656
13 UIKit                          0x18a4fcf50 -[UIApplication workspaceDidEndTransaction:] + 168
14 FrontBoardServices             0x18eae37c4 -[FBSSerialQueue _performNext] + 184
15 FrontBoardServices             0x18eae3b44 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
16 CoreFoundation                 0x184c7c544 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
17 CoreFoundation                 0x184c7bfd8 __CFRunLoopDoSources0 + 540
18 CoreFoundation                 0x184c79cd8 __CFRunLoopRun + 724
19 CoreFoundation                 0x184ba8ca0 CFRunLoopRunSpecific + 384
20 UIKit                          0x18a2c61c8 -[UIApplication _run] + 460
21 UIKit                          0x18a2c0ffc UIApplicationMain + 204
22 Registro Elettronico           0x10004a8b0 main (AppDelegate.swift:15)
23 libdyld.dylib                  0x19a0c68b8 start + 4

Steps to Reproduce

What are steps we can follow to reproduce this issue? I think that is something concerning background access, but i have done all the things described in the documentation.

Code Sample

Provide a code sample or test case that highlights the issue. If relevant, include your model definitions. For larger code samples, links to external gists/repositories are preferred. Alternatively share confidentially via mail to help@realm.io. Full Xcode projects that we can compile ourselves are ideal! if let ret = Database.realm.objects(Impostazioni).account().filter(NSPredicate(format: "chiave = %@", chiave)).first { return ret.valore }else{ return "" }

Version of Realm and Tooling

In the CONTRIBUTING guidelines, you will find a script, which will help determining these versions.

Realm version: ? 0.101.0 Xcode version: ? 7.3 iOS/OSX version: ? 9.3.1 Dependency manager + version: ? CocoaPods 1.0.0.rc.2

austinzheng commented 8 years ago

Hello! Thanks for reporting this problem, and sorry for the inconvenience.

Would you be willing to provide additional information in order to help us debug this issue? In particular:

Any other contextual information you can provide would be greatly appreciated. Thanks!

GZaccaroni commented 8 years ago

Hi @austinzheng, thanks for the reply.

Definition of the model:

class Impostazioni: Object {
    dynamic var aID = 0
    dynamic var chiave = ""
    dynamic var valore = ""
}

I'm using a static variable defined inside a class as

private static let realm = try! Realm()

I'm trying to fetch results from a thread and it sporadically happen (more than 1000 users experiences that crash)

austinzheng commented 8 years ago

Thanks! We will be investigating your bug report. I will let you know if I have further questions.

austinzheng commented 8 years ago

Hi @GZaccaroni,

Based on your stack trace and the information you provided it seems the problem is that the Realm() initializer is throwing an uncaught error, which causes the program to be terminated due to the try!.

Since this should happen only rarely (and almost certainly not for 30% of your users), would you be willing to change your code to catch the error and log the error message? This won't fix your problem, unfortunately, but it will provide us with additional data that can help us determine the root cause. (You can read more about how to extract the error message here: https://realm.io/docs/swift/latest/#error-handling)

Let me know if you have any questions or concerns, and thanks for your patience.

GZaccaroni commented 8 years ago

Ok i'll try to handle it, thanks!

Il giorno 10 mag 2016, alle ore 22:26, Austin Zheng notifications@github.com ha scritto:

Hi @GZaccaroni,

Based on your stack trace and the information you provided it seems the problem is that the Realm() initializer is throwing an uncaught error, which causes the program to be terminated due to the try!.

Since this should happen only rarely (and almost certainly not for 30% of your users), would you be willing to change your code to catch the error and log the error message? This won't fix your problem, unfortunately, but it will provide us with additional data that can help us determine the root cause. (You can read more about how to extract the error message here: https://realm.io/docs/swift/latest/#error-handling)

Let me know if you have any questions or concerns, and thanks for your patience.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

brod-ie commented 6 years ago

@GZaccaroni What were your findings?