{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/520","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/520/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/520/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/520/events","html_url":"https://github.com/petkaantonov/bluebird/issues/520","id":59518903,"number":520,"title":".cancel() can cause an infinite loop","user":{"login":"JLRishe","id":6964029,"avatar_url":"https://avatars.githubusercontent.com/u/6964029?v=3","gravatar_id":"","url":"https://api.github.com/users/JLRishe","html_url":"https://github.com/JLRishe","followers_url":"https://api.github.com/users/JLRishe/followers","following_url":"https://api.github.com/users/JLRishe/following{/other_user}","gists_url":"https://api.github.com/users/JLRishe/gists{/gist_id}","starred_url":"https://api.github.com/users/JLRishe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JLRishe/subscriptions","organizations_url":"https://api.github.com/users/JLRishe/orgs","repos_url":"https://api.github.com/users/JLRishe/repos","events_url":"https://api.github.com/users/JLRishe/events{/privacy}","received_events_url":"https://api.github.com/users/JLRishe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-03-02T18:09:30Z","updated_at":"2015-03-03T01:58:52Z","closed_at":null,"body":"It looks like there are certain situations where it's possible for `._cancel()` to enter a tight infinite loop that basically locks up the execution context:\r\n\r\nhttp://stackoverflow.com/questions/28811232/why-does-cancelling-a-bluebird-promise-in-a-callback-stop-setinterval/28815027#28815027\r\n\r\nThis can probably be chalked up to user error, but it seems like it would be possible to detect a cycle in the promise chain and avoid have everything come to a grinding halt.\r\n\r\nIt appears that there are talks about [overhauling the cancellation system](https://github.com/petkaantonov/bluebird/issues/415), but I wanted to make a note of this nonetheless, just in case safeguards could be added somewhere down the road."},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/76872281","html_url":"https://github.com/petkaantonov/bluebird/issues/520#issuecomment-76872281","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/520","id":76872281,"user":{"login":"petkaantonov","id":829734,"avatar_url":"https://avatars.githubusercontent.com/u/829734?v=3","gravatar_id":"","url":"https://api.github.com/users/petkaantonov","html_url":"https://github.com/petkaantonov","followers_url":"https://api.github.com/users/petkaantonov/followers","following_url":"https://api.github.com/users/petkaantonov/following{/other_user}","gists_url":"https://api.github.com/users/petkaantonov/gists{/gist_id}","starred_url":"https://api.github.com/users/petkaantonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petkaantonov/subscriptions","organizations_url":"https://api.github.com/users/petkaantonov/orgs","repos_url":"https://api.github.com/users/petkaantonov/repos","events_url":"https://api.github.com/users/petkaantonov/events{/privacy}","received_events_url":"https://api.github.com/users/petkaantonov/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T01:58:52Z","updated_at":"2015-03-03T01:58:52Z","body":"The purpose of cancellation is not related to control-flow but to cancel operations. Say you made a http request to fetch data for some widget, but the user closes that widget before it arrives. So in that case you want to cancel the request because it would otherwise complicated the resulting code that needs to check if the request was relevant anymore. It also frees up resources faster but it's not really relevant in this example."}}