Skip to content

fix: Use thread-safe caches in apicontroller#2523

Open
SystemKeeper wants to merge 1 commit into
mainfrom
fix/noid/threadsafe-cache-apicontroller
Open

fix: Use thread-safe caches in apicontroller#2523
SystemKeeper wants to merge 1 commit into
mainfrom
fix/noid/threadsafe-cache-apicontroller

Conversation

@SystemKeeper
Copy link
Copy Markdown
Collaborator

We've seen crashes in background fetch lately, e.g.

Thread 2 name:
Thread 2 Crashed:
0   libswiftCore.dylib            	0x00000001918a9980 swift_isUniquelyReferenced_nonNull_native + 0 (SwiftObject.mm:1493)
1   NextcloudTalk                 	0x0000000100f83bb0 specialized Dictionary._Variant.isUniquelyReferenced() + 8 (/<compiler-generated>:0)
2   NextcloudTalk                 	0x0000000100f83bb0 specialized Dictionary._Variant.setValue(_:forKey:) + 8 (/<compiler-generated>:0)
3   NextcloudTalk                 	0x0000000100f83bb0 specialized Dictionary.subscript.setter + 8 (NCAPIController.swift:73)
4   NextcloudTalk                 	0x0000000100f83bb0 NCAPIController.getAPISessionManager(forAccountId:) + 596
5   NextcloudTalk                 	0x0000000100f861c8 NCAPIController.getRooms(forAccount:updateStatus:modifiedSince:completionBlock:) + 108 (NCAPIController.swift:291)
6   NextcloudTalk                 	0x000000010101142c NCRoomsManager.updateRooms(updatingUserStatus:onlyLastModified:withCompletion:) + 876 (NCRoomsManager.swift:151)
7   NextcloudTalk                 	0x0000000101010644 NCRoomsManager.updateRoomsAndChats(updatingUserStatus:onlyLastModified:withCompletionBlock:) + 880 (NCRoomsManager.swift:93)
8   NextcloudTalk                 	0x0000000101011048 @objc NCRoomsManager.updateRoomsAndChats(updatingUserStatus:onlyLastModified:withCompletionBlock:) + 132 (/<compiler-generated>:0)
9   NextcloudTalk                 	0x0000000100e72aa0 -[AppDelegate performBackgroundFetchWithCompletionHandler:] + 460 (AppDelegate.m:566)
10  NextcloudTalk                 	0x0000000100e72808 -[AppDelegate handleAppRefresh:] + 120 (AppDelegate.m:506)
11  BackgroundTasks               	0x00000001bf74ddbc __41-[BGTaskScheduler _runTask:registration:]_block_invoke_5 + 228 (BGTaskScheduler.m:662)

This boils down to parallel access to the swift dictionaries we used, so use NSCache, which is thread-safe.

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
@SystemKeeper SystemKeeper requested a review from Ivansss May 24, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant