{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1256","labels_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1256/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1256/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1256/events","html_url":"https://github.com/ReactiveX/RxJS/issues/1256","id":129234493,"number":1256,"title":"Potential resource leak in unsubscribe loop","user":{"login":"briancavalier","id":90518,"avatar_url":"https://avatars.githubusercontent.com/u/90518?v=3","gravatar_id":"","url":"https://api.github.com/users/briancavalier","html_url":"https://github.com/briancavalier","followers_url":"https://api.github.com/users/briancavalier/followers","following_url":"https://api.github.com/users/briancavalier/following{/other_user}","gists_url":"https://api.github.com/users/briancavalier/gists{/gist_id}","starred_url":"https://api.github.com/users/briancavalier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briancavalier/subscriptions","organizations_url":"https://api.github.com/users/briancavalier/orgs","repos_url":"https://api.github.com/users/briancavalier/repos","events_url":"https://api.github.com/users/briancavalier/events{/privacy}","received_events_url":"https://api.github.com/users/briancavalier/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ReactiveX/RxJS/labels/priority:%20critical","name":"priority: critical","color":"eb6420"},{"url":"https://api.github.com/repos/ReactiveX/RxJS/labels/status:%20PRs%20welcome","name":"status: PRs welcome","color":"159818"},{"url":"https://api.github.com/repos/ReactiveX/RxJS/labels/type:%20bug","name":"type: bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ReactiveX/RxJS/milestones/5","html_url":"https://github.com/ReactiveX/RxJS/milestones/5.0.0-beta.2","labels_url":"https://api.github.com/repos/ReactiveX/RxJS/milestones/5/labels","id":1509593,"number":5,"title":"5.0.0-beta.2","description":"Things that need addressed for beta.2 release.","creator":{"login":"blesh","id":1540597,"avatar_url":"https://avatars.githubusercontent.com/u/1540597?v=3","gravatar_id":"","url":"https://api.github.com/users/blesh","html_url":"https://github.com/blesh","followers_url":"https://api.github.com/users/blesh/followers","following_url":"https://api.github.com/users/blesh/following{/other_user}","gists_url":"https://api.github.com/users/blesh/gists{/gist_id}","starred_url":"https://api.github.com/users/blesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blesh/subscriptions","organizations_url":"https://api.github.com/users/blesh/orgs","repos_url":"https://api.github.com/users/blesh/repos","events_url":"https://api.github.com/users/blesh/events{/privacy}","received_events_url":"https://api.github.com/users/blesh/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":7,"state":"open","created_at":"2016-01-15T19:56:53Z","updated_at":"2016-01-27T23:35:22Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2016-01-27T18:56:15Z","updated_at":"2016-01-29T18:13:59Z","closed_at":"2016-01-27T23:35:22Z","body":"Subscription [builds up an array of subscriptions in `add()`](https://github.com/ReactiveX/RxJS/blob/master/src/Subscription.ts#L71), which is later [torn down in a loop](https://github.com/ReactiveX/RxJS/blob/master/src/Subscription.ts#L40-L45) when unsubscribe() is called.  It seems that if a particular `subscription.unsubscribe` call throws, the subscriptions later in the array will never be unsubscribed.  If those subscriptions represent resources, perhaps from Observable.create calls as mentioned in [Guidelines bullet 4](https://github.com/ReactiveX/RxJS/blob/master/doc/operator-creation.md#guidelines), it appears that the resources would be leaked.\r\n\r\nIs there a potential leak there?"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJS/issues/comments/176893023","html_url":"https://github.com/ReactiveX/RxJS/issues/1256#issuecomment-176893023","issue_url":"https://api.github.com/repos/ReactiveX/RxJS/issues/1256","id":176893023,"user":{"login":"blesh","id":1540597,"avatar_url":"https://avatars.githubusercontent.com/u/1540597?v=3","gravatar_id":"","url":"https://api.github.com/users/blesh","html_url":"https://github.com/blesh","followers_url":"https://api.github.com/users/blesh/followers","following_url":"https://api.github.com/users/blesh/following{/other_user}","gists_url":"https://api.github.com/users/blesh/gists{/gist_id}","starred_url":"https://api.github.com/users/blesh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blesh/subscriptions","organizations_url":"https://api.github.com/users/blesh/orgs","repos_url":"https://api.github.com/users/blesh/repos","events_url":"https://api.github.com/users/blesh/events{/privacy}","received_events_url":"https://api.github.com/users/blesh/received_events","type":"User","site_admin":false},"created_at":"2016-01-29T18:13:59Z","updated_at":"2016-01-29T18:13:59Z","body":"> It's the same rule as in any language, you don't throw in finalizers, simple as that\r\n\r\nI'm unfamiliar with this rule or how it applies to this method call.\r\n\r\nPerhaps I'm just confused: Are you asking us to remove the memory leak protection code?\r\n\r\nBecause currently, it will:\r\n\r\n1. prevent memory leaks by completing unsubscriptions\r\n2. then throw synchronously\r\n\r\nand if we remove it:\r\n\r\n1. Allow memory leaks\r\n2. the throw synchronously\r\n\r\n\r\n\r\n... It seems pretty clear we should keep the code in there. We're protecting ourselves from user-land errors, since the unsubscribe function could be provided by users of the type."}}