Crash in ContactsSynchronizer
or-else opened this issue · comments
This is a fresh installation which has never logged in. It seems to assume that the database has been created.
#5 0x000000010d4a6558 in SubscriberDb.createTable() at /tinode/ios/Tinodios/db/SubscriberDb.swift:68
#6 0x000000010d3f31f5 in BaseDb.initDb() at /tinode/ios/Tinodios/db/BaseDb.swift:82
#7 0x000000010d3f3e8f in static BaseDb.getInstance() at /tinode/ios/Tinodios/db/BaseDb.swift:100
#8 0x000000010d3ee233 in ContactsManager.init() at /tinode/ios/Tinodios/account/ContactsManager.swift:32
#9 0x000000010d3ede30 in ContactsManager.__allocating_init() ()
#10 0x000000010d3edddc in globalinit_33_4AE933758BA578E6197EF98E870A28F2_func0 /tinode/ios/Tinodios/account/ContactsManager.swift:27
#11 0x0000000111b7ddb5 in _dispatch_client_callout ()
#12 0x0000000111b7f83c in _dispatch_once_callout ()
#13 0x00000001111f6579 in swift_once ()
#14 0x000000010d3edeb4 in ContactsManager.default.unsafeMutableAddressor at /tinode/ios/Tinodios/account/ContactsManager.swift:27
#15 0x000000010d3a28f6 in ContactsSynchronizer.synchronizeInternal() at /tinode/ios/Tinodios/account/ContactsSynchronizer.swift:125
#16 0x000000010d39f7ab in closure #1 in ContactsSynchronizer.authStatus.didset at /tinode/ios/Tinodios/account/ContactsSynchronizer.swift:45
Crashes about once in 3 runs.
I can't reproduce this.
Do you have the rest of the stack trace and the error message by any chance?
I cannot reproduce it today. It's been happening regularly yesterday. I'll collect more info if I see it again.
Got it again today. This is the entire call stack. It crashes immediately on startup while logged out.
#0 0x0000000106102b50 in _swift_runtime_on_report ()
#1 0x00000001061624e8 in _swift_stdlib_reportFatalError ()
#2 0x00000001060624d6 in specialized closure #2 in _fatalErrorMessage(_:_:file:line:flags:) ()
#3 0x0000000106062853 in specialized _fatalErrorMessage(_:_:file:line:flags:) ()
#4 0x0000000105e5df83 in _fatalErrorMessage(_:_:file:line:flags:) ()
#5 0x00000001023d2c48 in SubscriberDb.createTable() at /Users/gene/ventures/tinode/ios/Tinodios/db/SubscriberDb.swift:68
#6 0x00000001023214f5 in BaseDb.initDb() at /Users/gene/ventures/tinode/ios/Tinodios/db/BaseDb.swift:82
#7 0x000000010232218f in static BaseDb.getInstance() at /Users/gene/ventures/tinode/ios/Tinodios/db/BaseDb.swift:100
#8 0x000000010231c343 in ContactsManager.init() at /Users/gene/ventures/tinode/ios/Tinodios/account/ContactsManager.swift:32
#9 0x000000010231bf40 in ContactsManager.__allocating_init() ()
#10 0x000000010231beec in globalinit_33_4AE933758BA578E6197EF98E870A28F2_func0 at /Users/gene/ventures/tinode/ios/Tinodios/account/ContactsManager.swift:27
#11 0x0000000106aacdb5 in _dispatch_client_callout ()
#12 0x0000000106aae83c in _dispatch_once_callout ()
#13 0x0000000106125579 in swift_once ()
#14 0x000000010231bfc4 in ContactsManager.default.unsafeMutableAddressor at /Users/gene/ventures/tinode/ios/Tinodios/account/ContactsManager.swift:27
#15 0x00000001022cfcf6 in ContactsSynchronizer.synchronizeInternal() at /Users/gene/ventures/tinode/ios/Tinodios/account/ContactsSynchronizer.swift:125
#16 0x00000001022ccbab in closure #1 in ContactsSynchronizer.authStatus.didset at /Users/gene/ventures/tinode/ios/Tinodios/account/ContactsSynchronizer.swift:45
#17 0x00000001022d411c in partial apply for closure #1 in ContactsSynchronizer.authStatus.didset ()
#18 0x000000010229718d in thunk for @escaping @callee_guaranteed () -> () ()
#19 0x0000000106aabd7f in _dispatch_call_block_and_release ()
#20 0x0000000106aacdb5 in _dispatch_client_callout ()
#21 0x0000000106ab4225 in _dispatch_lane_serial_drain ()
#22 0x0000000106ab4e9c in _dispatch_lane_invoke ()
#23 0x0000000106abeea3 in _dispatch_workloop_worker_thread ()
#24 0x0000000106f5a611 in _pthread_wqthread ()
#25 0x0000000106f5a3fd in start_wqthread ()
let topicDb = BaseDb.getInstance().topicDb!
is nil.
I don't see the immediate reason for the crash but there is a logical problem in initialization of ContactsManager:
ContactsManager.init()
callsBaseDb.getInstance()
- If it's been initialized, it returns
BaseDb.default
- all is fine. - If it's not yet initialized, it proceeds to initialize it by calling
BaseDb.initDb()
BaseDb.initDb()
makes calls toself.xxxxDb!.createTable()
- And
self.xxxxDb!.createTable()
callsBaseDb.getInstance()
which returns assigned but not fully initializedBaseDb.default
!
My guess it's a race condition due to the timing of the run of synchronizeContactsPeriodically
: if it happens to be run before DB is initialized by other means the app crashes. Otherwise it's fine.
Thanks for discovering this.
I'll also refactor createTable()
to not use BaseDb.getInstance().
I think it's fixed. I have not seen these crashes for a long time. I'm closing.