File tree Expand file tree Collapse file tree
Source/SwiftyDropbox/Shared/Handwritten Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -241,8 +241,19 @@ class RequestWithTokenRefresh: ApiRequest {
241241 self . filesAccess = filesAccess
242242
243243 let setTask = {
244+ // It is important to run this block, which may do a lot of work outside the SDK,
245+ // before getting the lock. We have seen deadlock scenarios like the following:
246+ // 1. Enter thread safe code behind a lock in your app
247+ // 2. Start a request from behind that lock in your app
248+ // 3. We would get the access state lock below before executing requestCreation()
249+ // 4. This request creation block eventually goes back out to your app's code to get headers
250+ // 5. Once in your app's code, it needs to go into the code locked in step 1 to get info for headers
251+ // 6. Deadlock
252+ //
253+ // Because we don't have contention between threads to run the requestCreation() block,
254+ // it can be omitted from the locked section.
255+ let task = requestCreation ( )
244256 self . accessStateWithLock { state in
245- let task = requestCreation ( )
246257 state. request = task
247258 state. handleRequestCreation ( )
248259 }
You can’t perform that action at this time.
0 commit comments