{"action":"created","issue":{"url":"https://api.github.com/repos/openshift/origin/issues/4247","labels_url":"https://api.github.com/repos/openshift/origin/issues/4247/labels{/name}","comments_url":"https://api.github.com/repos/openshift/origin/issues/4247/comments","events_url":"https://api.github.com/repos/openshift/origin/issues/4247/events","html_url":"https://github.com/openshift/origin/issues/4247","id":101729231,"number":4247,"title":"$rootScope.$apply() in DataService.get() causes looping errors","user":{"login":"benjaminapetersen","id":280512,"avatar_url":"https://avatars.githubusercontent.com/u/280512?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminapetersen","html_url":"https://github.com/benjaminapetersen","followers_url":"https://api.github.com/users/benjaminapetersen/followers","following_url":"https://api.github.com/users/benjaminapetersen/following{/other_user}","gists_url":"https://api.github.com/users/benjaminapetersen/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminapetersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminapetersen/subscriptions","organizations_url":"https://api.github.com/users/benjaminapetersen/orgs","repos_url":"https://api.github.com/users/benjaminapetersen/repos","events_url":"https://api.github.com/users/benjaminapetersen/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminapetersen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"benjaminapetersen","id":280512,"avatar_url":"https://avatars.githubusercontent.com/u/280512?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminapetersen","html_url":"https://github.com/benjaminapetersen","followers_url":"https://api.github.com/users/benjaminapetersen/followers","following_url":"https://api.github.com/users/benjaminapetersen/following{/other_user}","gists_url":"https://api.github.com/users/benjaminapetersen/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminapetersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminapetersen/subscriptions","organizations_url":"https://api.github.com/users/benjaminapetersen/orgs","repos_url":"https://api.github.com/users/benjaminapetersen/repos","events_url":"https://api.github.com/users/benjaminapetersen/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminapetersen/received_events","type":"User","site_admin":false},"milestone":null,"comments":15,"created_at":"2015-08-18T19:16:12Z","updated_at":"2015-09-02T16:40:15Z","closed_at":null,"body":"There is a call to `$rooteScope.$apply()` in DataService.get() that can cause Angular to throw `$digest` errors:\r\n\r\n`Error: [$rootScope:inprog] $digest already in progress\r\nhttp://errors.angularjs.org/1.3.8/$rootScope/inprog?p0=%24digest`\r\n\r\nA string of promises in controller code is an example of what can trigger this error.  A slimmed down example of what can potentially cause this:\r\n\r\n```javascript\r\n\r\nAuthService\r\n  .withUser()\r\n  .then(function(user) {\r\n     return DataService\r\n                  .get('projects', projectName, context)\r\n                  .then(function(project) {\r\n                    angular.extend($scope, {\r\n                      project: project\r\n                    });\r\n                    return project;\r\n                  });\r\n  })\r\n  .then(function(user) {\r\n     return DataService\r\n                  .get('builds', buildName, context)\r\n                  .then(function(build) {\r\n                    angular.extend($scope, {\r\n                      build: build\r\n                    })\r\n                    return build;\r\n                  });\r\n  });\r\n```\r\n\r\nThe block of code that causes the issue (lines 277-292 of data.js):\r\n\r\n```javascript\r\nif (obj) {\r\n  $rootScope.$apply(function(){\r\n    deferred.resolve(obj);\r\n  });\r\n}\r\nelse {\r\n  $rootScope.$apply(function(){\r\n    // simulation of API object not found\r\n    deferred.reject({\r\n      data: {},\r\n      status: 404,\r\n      headers: function() { return null; },\r\n      config: {}\r\n    });\r\n  });\r\n} \r\n```\r\n\r\nEliminating the `$rootScope.$apply()` calls does not initially seem to cause issues, but it may be in order to have QE do a regression test.  The block would now look like:\r\n\r\n```javascript\r\nif (obj) {\r\n  deferred.resolve(obj);\r\n}\r\nelse {\r\n    // simulation of API object not found\r\n  deferred.reject({\r\n      data: {},\r\n      status: 404,\r\n      headers: function() { return null; },\r\n      config: {}\r\n  });\r\n} \r\n```\r\n\r\nThe [docs for root scope](https://docs.angularjs.org/error/$rootScope/inprog?p0=$digest) discourage using `$rootScope.$apply()` in this way, particularly under the heading \"Digest Phases\".  \r\n\r\nI propose eliminating these lines unless there is good reason to keep them.  \r\n\r\n@jwforres @spadgett any concerns with this change?"},"comment":{"url":"https://api.github.com/repos/openshift/origin/issues/comments/137163850","html_url":"https://github.com/openshift/origin/issues/4247#issuecomment-137163850","issue_url":"https://api.github.com/repos/openshift/origin/issues/4247","id":137163850,"user":{"login":"spadgett","id":1167259,"avatar_url":"https://avatars.githubusercontent.com/u/1167259?v=3","gravatar_id":"","url":"https://api.github.com/users/spadgett","html_url":"https://github.com/spadgett","followers_url":"https://api.github.com/users/spadgett/followers","following_url":"https://api.github.com/users/spadgett/following{/other_user}","gists_url":"https://api.github.com/users/spadgett/gists{/gist_id}","starred_url":"https://api.github.com/users/spadgett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spadgett/subscriptions","organizations_url":"https://api.github.com/users/spadgett/orgs","repos_url":"https://api.github.com/users/spadgett/repos","events_url":"https://api.github.com/users/spadgett/events{/privacy}","received_events_url":"https://api.github.com/users/spadgett/received_events","type":"User","site_admin":false},"created_at":"2015-09-02T16:40:15Z","updated_at":"2015-09-02T16:40:15Z","body":"@liggitt looks like the calling code where @benjaminapetersen originally saw the problem is still in the logs pull."}}