Hi, I am building a mobile application using swift and couchbase lite with replication. I am having issues with logging out. Right now, I can successfully logout a user upon request with this code:
func close() throws {
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
self.replicator.addChangeListener { (change) in
if change.status.activity == .stopped {
dispatchGroup.leave()
}
}
self.replicator.stop()
dispatchGroup.wait()
do {
self.queryListenerToken?.remove()
replicatorStatusToken?.remove()
try database?.close()
database = nil;
clearData()
} catch {
throw DataRetrievalIssue(message: "this is bad")
}
}
func clearData() {
queryMyTasks = nil
queryAllTasks = nil
queryListenerToken = nil
collections = [:]
}
And if I close the app simulator, I can then restart the simulator and login with the same or different user. However, if I attempt to login with a user after logging out (without terminating the app simulator), I get this error:
Thread 1: âAttempt to perform an operation on a closed database or a deleted collection.â
This is the backtrace:
CouchbaseLite Database ERROR: FATAL ERROR (backtrace follows)
Uncaught exception:
unknown exception type
Backtrace:
******************** NOW TERMINATING
*** Terminating app due to uncaught exception âNSInternalInconsistencyExceptionâ, reason: âAttempt to perform an operation on a closed database or a deleted collection.â
*** First throw call stack:
(
0 CoreFoundation 0x00007ff80049b761 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff800063904 objc_exception_throw + 48
2 CoreFoundation 0x00007ff80049b63f -[NSException initWithCoder:] + 0
3 CouchbaseLiteSwift 0x00000001094ec18e _Z26sliceResult2FilesystemPath13FLSliceResult + 37053
4 CouchbaseLiteSwift 0x00000001094f55a9 Z26toSecIdentityWithCertChainP6C4CertPU15__autoreleasingP7NSError + 10408
5 CouchbaseLiteSwift 0x00000001094f3987 Z26toSecIdentityWithCertChainP6C4CertPU15__autoreleasingP7NSError + 3206
6 CouchbaseLiteSwift 0x00000001094f47d6 Z26toSecIdentityWithCertChainP6C4CertPU15__autoreleasingP7NSError + 6869
7 CouchbaseLiteSwift 0x0000000109505002 CBLLog_GetDomainName + 44795
8 CouchbaseLiteSwift 0x000000010943f049 CouchbaseLiteSwift + 118857
9 CouchbaseLiteSwift 0x000000010943f0f6 CouchbaseLiteSwift + 119030
10 CouchbaseLiteSwift 0x000000010943e7e5 CouchbaseLiteSwift + 116709
11 CouchbaseLiteSwift 0x000000010943f9fe CouchbaseLiteSwift + 121342
12 PlaitePlannerApplication 0x0000000106a9ec72 $s24PlaitePlannerApplication14PlannedMealDAOC15findByDateRange5start3end7ownerIdSayAA0dE0VG10Foundation0I0V_AMSStKF + 2626
13 PlaitePlannerApplication 0x0000000106a9e134 $s24PlaitePlannerApplication14PlannedMealDAOC10findByDate_7ownerIdSayAA0dE0VG10Foundation0I0V_SStKF + 708
14 PlaitePlannerApplication 0x0000000106aa1f6b $s24PlaitePlannerApplication14PlannedMealDAOCAA0dE11DAOProtocolA2aDP10findByDate_7ownerIdSayAA0dE0VG10Foundation0J0V_SStKFTW + 27
15 PlaitePlannerApplication 0x0000000106bd1d84 $s24PlaitePlannerApplication21MealPlanningViewModelC19refreshPlannedMealsyyYaKFTY2 + 308
16 PlaitePlannerApplication 0x0000000106bd14b1 $s24PlaitePlannerApplication21MealPlanningViewModelC13setupBindings33_D101B7252819B237F178A86391869A85LLyyFy10Foundation4DateVcfU_ytSgyYaYbKcfU_TQ1 + 1
17 PlaitePlannerApplication 0x0000000106bd5261 $s24PlaitePlannerApplication21MealPlanningViewModelC13setupBindings33_D101B7252819B237F178A86391869A85LLyyFy10Foundation4DateVcfU_ytSgyYaYbKcfU_TATQ0 + 1
18 libswift_Concurrency.dylib 0x00007ff85b008d11 _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
)
libc++abi: terminating due to uncaught exception of type NSException
I am authenticating with OIDC btw. Is there anything I am missing with my logout logic? I canât find any resources online to help with this issue.