leighmcculloch / AppSandboxFileAccess

A class that wraps up writing and accessing files outside a Mac apps App Sandbox files into a simple interface. The class will request permission from the user with a simple to understand dialog consistent with Apple's documentation and persist permissions across application runs.
BSD 2-Clause "Simplified" License
114 stars 23 forks source link

Don't deadlock if askPermissionForUrl: is called from the main queue. #1

Closed vslavik closed 10 years ago

vslavik commented 10 years ago

dispatch_sync() is documented to deadlock if the target queue is the same as the current one. This happens when AppSandboxFileAccess is used from the main thread. Fix the deadlock by explicitly checking for the current queue and calling the block directly.

leighmcculloch commented 10 years ago

Thanks for picking this up @vslavik. How was this getting executed on the main queue?

vslavik commented 10 years ago

As said in the description: when you use e.g. accessFileURL:withBlock:persistPermission: from the main queue. Which may e.g. when you're doing some real quick that is not worth offloading to a worker thread or when, like me, you have old code that is not threaded well.

leighmcculloch commented 10 years ago

@vslavik I've fixed this in branch release/1.0.13, could you let me know if this resolves the issues you had?

vslavik commented 10 years ago

It does, thanks.

leighmcculloch commented 10 years ago

Thanks for finding the issue and a solution. :blush: