dropbox-sdk-obj-c icon indicating copy to clipboard operation
dropbox-sdk-obj-c copied to clipboard

Completion handler can get overwritten for longpoll sessions

Open bellissimo opened this issue 2 months ago • 1 comments

Dropbox SDK: 7.4.1 iOS 26.1

When using a longpoll session, for example when calling:

[self.client.filesRoutes listFolderLongpoll:cursor]

it uses a separate NSURLSession with a longer timeout than the usual session. However the code which stores data relating to the task (e.g. completion handlers), does so using a key of the 'task identifier', such as this code from DBDelegate.m

[sessionData.completionData removeObjectForKey:taskId]

The task id is unique only to the NSURLSession, so you can end up, for example, with a normal request (e.g. getCurrentAccount) creating a task with an id of 1 and a longpoll session (e.g. listFolderLongpoll) also creating a task with an id of 1. When the normal request completes, it then removes its completion handler from the data using the key of 1. As both tasks have the same task id, then the listFolderLongpoll task gets its completion handler removed and can lead to a stuck thread which no longer reports back any changed data.

The solution is to create a key for the task data composed of both a session id and a task id, where you have a different session id for the normal session and the longpoll session.

bellissimo avatar Oct 31 '25 09:10 bellissimo

Thanks for the detailed report! I've sent this to the team. We'll follow up here with any updates.

greg-db avatar Nov 04 '25 20:11 greg-db

sessionData is per session, so a taskId is a sufficiently unique identifier. However the longpoll session and default foreground session were getting the same sesssionId. Fixed in https://github.com/dropbox/dropbox-sdk-obj-c/pull/391

jaquish avatar Dec 15 '25 17:12 jaquish