{"action":"closed","issue":{"url":"https://api.github.com/repos/seatgeek/SGHTTPRequest/issues/3","labels_url":"https://api.github.com/repos/seatgeek/SGHTTPRequest/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/seatgeek/SGHTTPRequest/issues/3/comments","events_url":"https://api.github.com/repos/seatgeek/SGHTTPRequest/issues/3/events","html_url":"https://github.com/seatgeek/SGHTTPRequest/issues/3","id":95139272,"number":3,"title":"Race condition, likely causing crash in SGHTTPRequest","user":{"login":"pyrtsa","id":212795,"avatar_url":"https://avatars.githubusercontent.com/u/212795?v=3","gravatar_id":"","url":"https://api.github.com/users/pyrtsa","html_url":"https://github.com/pyrtsa","followers_url":"https://api.github.com/users/pyrtsa/followers","following_url":"https://api.github.com/users/pyrtsa/following{/other_user}","gists_url":"https://api.github.com/users/pyrtsa/gists{/gist_id}","starred_url":"https://api.github.com/users/pyrtsa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyrtsa/subscriptions","organizations_url":"https://api.github.com/users/pyrtsa/orgs","repos_url":"https://api.github.com/users/pyrtsa/repos","events_url":"https://api.github.com/users/pyrtsa/events{/privacy}","received_events_url":"https://api.github.com/users/pyrtsa/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-15T08:58:27Z","updated_at":"2015-09-02T05:18:01Z","closed_at":"2015-09-02T05:18:00Z","body":"The use of `gReachabilityManagers` in [SGHTTPRequest.m lines 215–219](https://github.com/seatgeek/SGHTTPRequest/blob/b0c0a18c84bfa10c1a4feef89f1c3bb14a7d73c3/SGHTTPRequest.m#L215-L219) is unsynchronised, which seems to me it can cause a race condition, leading to possible crashes.\r\n\r\nIndeed, we're seeing the following crash dump, which I can't attribute to anything else than that (I might be wrong or just miss a detail, of course):\r\n\r\n```\r\nThread : Crashed: NSOperationQueue 0x170e27040 :: NSOperation 0x1704b01a0 (QOS: USER_INITIATED)\r\n0  libsystem_kernel.dylib         0x00000001951bf270 __pthread_kill + 8\r\n1  libsystem_pthread.dylib        0x000000019525d170 pthread_kill + 112\r\n2  libsystem_c.dylib              0x0000000195136b18 abort + 112\r\n3  libsystem_malloc.dylib         0x00000001951ec2fc szone_size + 510\r\n4  CoreFoundation                 0x0000000182d24064 __rehashd + 244\r\n5  CoreFoundation                 0x0000000182c11324 -[__NSDictionaryM setObject:forKey:] + 712\r\n6  SGHTTPRequest                  0x00000001009dd61c +[SGHTTPRequest managerForBaseURL:requestType:responseType:] + 708\r\n7  SGHTTPRequest                  0x00000001009dca20 -[SGHTTPRequest start] + 340\r\n8  SGImageCache                   0x00000001009f9cd8 -[SGCacheTask fetchRemoteFile] + 1116\r\n9  Foundation                     0x0000000183c11f28 __NSOQSchedule_f + 228\r\n10 libdispatch.dylib              0x0000000195079954 _dispatch_client_callout + 16\r\n11 libdispatch.dylib              0x00000001950840a4 _dispatch_queue_drain + 1448\r\n12 libdispatch.dylib              0x000000019507ca5c _dispatch_queue_invoke + 132\r\n13 libdispatch.dylib              0x0000000195086318 _dispatch_root_queue_drain + 720\r\n14 libdispatch.dylib              0x0000000195087c4c _dispatch_worker_thread3 + 108\r\n15 libsystem_pthread.dylib        0x000000019525922c _pthread_wqthread + 816\r\n16 libsystem_pthread.dylib        0x0000000195258ef0 start_wqthread + 4\r\n```\r\n\r\nThis should be a simple thing to fix (just use `dispatch_sync` with a serial queue when reading or writing `gReachabilityManagers`), but I can send a pull request a bit later, if you like me to."}}