{"action":"created","issue":{"url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/14","repository_url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator","labels_url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/14/comments","events_url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/14/events","html_url":"https://github.com/Alamofire/AlamofireNetworkActivityIndicator/issues/14","id":175273477,"number":14,"title":"Spinner can be left up indefinitely","user":{"login":"graham-perks-snap","id":16227778,"avatar_url":"https://avatars.githubusercontent.com/u/16227778?v=3","gravatar_id":"","url":"https://api.github.com/users/graham-perks-snap","html_url":"https://github.com/graham-perks-snap","followers_url":"https://api.github.com/users/graham-perks-snap/followers","following_url":"https://api.github.com/users/graham-perks-snap/following{/other_user}","gists_url":"https://api.github.com/users/graham-perks-snap/gists{/gist_id}","starred_url":"https://api.github.com/users/graham-perks-snap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graham-perks-snap/subscriptions","organizations_url":"https://api.github.com/users/graham-perks-snap/orgs","repos_url":"https://api.github.com/users/graham-perks-snap/repos","events_url":"https://api.github.com/users/graham-perks-snap/events{/privacy}","received_events_url":"https://api.github.com/users/graham-perks-snap/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/labels/bug","name":"bug","color":"ff3333"},{"url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/labels/delay%20timers","name":"delay timers","color":"69B805"},{"url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/labels/needs%20investigation","name":"needs investigation","color":"9559F0"}],"state":"open","locked":false,"assignee":{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false},"assignees":[{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-09-06T15:12:52Z","updated_at":"2016-09-21T18:08:28Z","closed_at":null,"body":"The indicator works great. However there's a threading issue in decrementActivityCount().\r\n\r\nThis has a line:\r\n\r\n    guard activityCount > 0 else { return }\r\n\r\nTo prevent the activityCount going negative. (I'm curious why this line was introduced.) I have a situation where the activityCount would go negative. The debugger hits the `else` part of the guard. I believe the timing hole is around AlamoFire's resume() method.\r\n\r\nAlamoFire's Request.resume() method (I added the comments):\r\n\r\n    public func resume() {\r\n        if startTime == nil { startTime = CFAbsoluteTimeGetCurrent() }\r\n\r\n        task.resume()\r\n\r\n        // TIMING HOLE HERE. \r\n        // The task comes back fast (e.g. from cache) before we call postNotificationName. \r\n        // The decrement is called in the result callback, and activityCount should go to -1. (But doesn't due to the guard > 0)\r\n        // Then this thread resumes and posts its notification about the task starting.\r\n        // Now the activity indicator's count is 1... forever above zero, so the indicator stays on.\r\n        NSNotificationCenter.defaultCenter().postNotificationName(Notifications.Task.DidResume, object: task)\r\n    }\r\n\r\nI see no reason for the `guard activityCount > 0` line. Removing it would fix this hole. "},"comment":{"url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/comments/248694851","html_url":"https://github.com/Alamofire/AlamofireNetworkActivityIndicator/issues/14#issuecomment-248694851","issue_url":"https://api.github.com/repos/Alamofire/AlamofireNetworkActivityIndicator/issues/14","id":248694851,"user":{"login":"gereons","id":2861931,"avatar_url":"https://avatars.githubusercontent.com/u/2861931?v=3","gravatar_id":"","url":"https://api.github.com/users/gereons","html_url":"https://github.com/gereons","followers_url":"https://api.github.com/users/gereons/followers","following_url":"https://api.github.com/users/gereons/following{/other_user}","gists_url":"https://api.github.com/users/gereons/gists{/gist_id}","starred_url":"https://api.github.com/users/gereons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gereons/subscriptions","organizations_url":"https://api.github.com/users/gereons/orgs","repos_url":"https://api.github.com/users/gereons/repos","events_url":"https://api.github.com/users/gereons/events{/privacy}","received_events_url":"https://api.github.com/users/gereons/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T18:08:28Z","updated_at":"2016-09-21T18:08:28Z","body":"I'm seeing the same symptoms, albeit not caused by that `guard`, when using SwiftyDropbox - on an otherwise idle system, when all Dropbox API requests are done, `activityCount` remains at 1."}}
{"actor":{"display_login":"gereons"}}