{"action":"opened","issue":{"url":"https://api.github.com/repos/zwopple/PocketSocket/issues/55","repository_url":"https://api.github.com/repos/zwopple/PocketSocket","labels_url":"https://api.github.com/repos/zwopple/PocketSocket/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/zwopple/PocketSocket/issues/55/comments","events_url":"https://api.github.com/repos/zwopple/PocketSocket/issues/55/events","html_url":"https://github.com/zwopple/PocketSocket/issues/55","id":166664952,"number":55,"title":"Deadlock or crash in -[PSWebSocket dealloc]","user":{"login":"snej","id":43241,"avatar_url":"https://avatars.githubusercontent.com/u/43241?v=3","gravatar_id":"","url":"https://api.github.com/users/snej","html_url":"https://github.com/snej","followers_url":"https://api.github.com/users/snej/followers","following_url":"https://api.github.com/users/snej/following{/other_user}","gists_url":"https://api.github.com/users/snej/gists{/gist_id}","starred_url":"https://api.github.com/users/snej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snej/subscriptions","organizations_url":"https://api.github.com/users/snej/orgs","repos_url":"https://api.github.com/users/snej/repos","events_url":"https://api.github.com/users/snej/events{/privacy}","received_events_url":"https://api.github.com/users/snej/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-20T19:42:51Z","updated_at":"2016-07-20T19:42:51Z","closed_at":null,"body":"Occasionally -[PSWebSocket dealloc] will either deadlock (iOS ≤ 9) or crash (iOS 10). The cause is the same — calling `dispatch_barrier_sync(_workQueue, ...)` when it's already running on the `_workQueue`. The behavior changes because libDispatch in iOS 10 [and presumably macOS 10.12] detects the deadlock condition and triggers a crash instead, adding to the crash report \"CRASH_INFO_ENTRY_0 BUG IN CLIENT OF LIBDISPATCH: dispatch_barrier_sync called on queue already owned by current thread\".\r\n\r\nI am not sure how to fix this. The PSWebSocket is used on multiple queues/threads, so it's indeterminate which of those will make the last -release call and trigger -dealloc. If it happens to be the workQueue, the synchronous GCD dispatch to it will deadlock.\r\n\r\nBut I'm not sure removing the GCD call is not a good fix because, if -dealloc runs on a different queue, the -disconnect method would run on that queue, violating thread-safety.\r\n\r\nOn the other other hand, though, if the object is in -dealloc, that implies no other threads have references to it so there couldn't be simultaneous calls to it on other threads. Which means it should be thread-safe to operate on its ivars.\r\n\r\n(FYI, there was an old abandoned PR #26 for doing exactly this.)"}}
{"actor":{"display_login":"snej"}}