{"action":"created","issue":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1303","repository_url":"https://api.github.com/repos/petkaantonov/bluebird","labels_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1303/labels{/name}","comments_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1303/comments","events_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1303/events","html_url":"https://github.com/petkaantonov/bluebird/issues/1303","id":195695756,"number":1303,"title":"Disposer is not called when promise is cancelled","user":{"login":"xmirya","id":3471545,"avatar_url":"https://avatars.githubusercontent.com/u/3471545?v=3","gravatar_id":"","url":"https://api.github.com/users/xmirya","html_url":"https://github.com/xmirya","followers_url":"https://api.github.com/users/xmirya/followers","following_url":"https://api.github.com/users/xmirya/following{/other_user}","gists_url":"https://api.github.com/users/xmirya/gists{/gist_id}","starred_url":"https://api.github.com/users/xmirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xmirya/subscriptions","organizations_url":"https://api.github.com/users/xmirya/orgs","repos_url":"https://api.github.com/users/xmirya/repos","events_url":"https://api.github.com/users/xmirya/events{/privacy}","received_events_url":"https://api.github.com/users/xmirya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-15T01:52:29Z","updated_at":"2016-12-15T02:12:31Z","closed_at":null,"body":"Bluebird version: 3.1.8\r\nNode.js: 7.2.1\r\n\r\nConsider the following example code:\r\n```javascript\r\nconst Promise = require('bluebird');\r\nPromise.config({\r\n    cancellation: true\r\n});\r\nconst acqPromise = new Promise(function (resolve, reject) {\r\n    setTimeout(resolve, 1000);\r\n});\r\nconst disposer = acqPromise.disposer(function () {\r\n    console.log('DISPOSER CALLED');\r\n});\r\nconst promise = Promise.using(disposer, function () {\r\n    return Promise.resolve();\r\n});\r\npromise.cancel();\r\n```\r\n\r\n`DISPOSER CALLED` is never printed in this example (and it _is_ printed when `promise.cancel()` is not called).\r\n\r\nA real-world example of this behavior impact is Knex.js, a database access library that uses Bluebird promises; Disposer interface is used to acquire and release database connections from the pool, so when a query promise is created and canceled like this, the connection gets actually acquired and never released, draining the pool and hanging up the application."},"comment":{"url":"https://api.github.com/repos/petkaantonov/bluebird/issues/comments/267217022","html_url":"https://github.com/petkaantonov/bluebird/issues/1303#issuecomment-267217022","issue_url":"https://api.github.com/repos/petkaantonov/bluebird/issues/1303","id":267217022,"user":{"login":"spion","id":502412,"avatar_url":"https://avatars.githubusercontent.com/u/502412?v=3","gravatar_id":"","url":"https://api.github.com/users/spion","html_url":"https://github.com/spion","followers_url":"https://api.github.com/users/spion/followers","following_url":"https://api.github.com/users/spion/following{/other_user}","gists_url":"https://api.github.com/users/spion/gists{/gist_id}","starred_url":"https://api.github.com/users/spion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spion/subscriptions","organizations_url":"https://api.github.com/users/spion/orgs","repos_url":"https://api.github.com/users/spion/repos","events_url":"https://api.github.com/users/spion/events{/privacy}","received_events_url":"https://api.github.com/users/spion/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T02:12:31Z","updated_at":"2016-12-15T02:12:31Z","body":"```js\r\nPromise.using(disposer, f) \r\n```\r\n\r\nshould desugar to\r\n\r\n```js\r\ndisposerPromise.then(f).finally(disposeFn)\r\n```\r\n\r\nand in this case, it looks like it doesn't.\r\n"}}
{"actor":{"display_login":"spion"}}