{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3070","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3070/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3070/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3070/events","html_url":"https://github.com/sequelize/sequelize/issues/3070","id":56942373,"number":3070,"title":"2.0.0 - rc8 Parallel findOrCreate calls dead lock","user":{"login":"EToreo","id":1248716,"avatar_url":"https://avatars.githubusercontent.com/u/1248716?v=3","gravatar_id":"","url":"https://api.github.com/users/EToreo","html_url":"https://github.com/EToreo","followers_url":"https://api.github.com/users/EToreo/followers","following_url":"https://api.github.com/users/EToreo/following{/other_user}","gists_url":"https://api.github.com/users/EToreo/gists{/gist_id}","starred_url":"https://api.github.com/users/EToreo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EToreo/subscriptions","organizations_url":"https://api.github.com/users/EToreo/orgs","repos_url":"https://api.github.com/users/EToreo/repos","events_url":"https://api.github.com/users/EToreo/events{/privacy}","received_events_url":"https://api.github.com/users/EToreo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/bug","name":"bug","color":"d7e102"}],"state":"open","locked":false,"assignee":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"milestone":null,"comments":22,"created_at":"2015-02-08T07:26:44Z","updated_at":"2015-02-10T19:25:34Z","closed_at":null,"body":"When I parallelize calls to findOrCreate, a deadlock is happening.  `\"Try to create employee...\"` prints out 12 times, but the all promise is never realized when I run the script the first time.  Enough subseqent re-executions of the script eventually allows the all promise to be realized and the `'Found or created all users'` printout.\r\n\r\nExample call:\r\n\r\n```javascript\r\n      all([\r\n         this._createUser('Jerry', 'Hatten'),\r\n         this._createUser('Linda', 'Dardar'),\r\n         this._createUser('Marcus', 'Keck'),\r\n         this._createUser('Andrea', 'Cutler'),\r\n         this._createUser('Eugene', 'Gullickson'),\r\n         this._createUser('Betty', 'Jones'),\r\n         this._createUser('Curtis', 'Bryant'),\r\n         this._createUser('Carl', 'Lebrun'),\r\n         this._createUser('Patricia', 'Hohl'),\r\n         this._createUser('Edward', 'Johnson'),\r\n         this._createUser('Phil', 'Louviere'),\r\n         this._createUser('Charles', 'Born')\r\n      ]).then(function(users)\r\n      {\r\n         console.log('Found or created all users');\r\n      }.bind(this), function(err) { deferred.reject(err); });\r\n```\r\n\r\n```javascript\r\nvar _createUser = function(nameFirst, nameLast)\r\n{\r\n   console.log('Try to create employee...');\r\n   var deferred = new Deferred();\r\n   db['User'].findOrCreate({...}).spread(function(user, created)\r\n   {\r\n       deferred.resolve(user);\r\n   }.bind(this)).catch(function(err) { deferred.reject(err); });\r\n   return deferred.promise;\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/73765346","html_url":"https://github.com/sequelize/sequelize/issues/3070#issuecomment-73765346","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3070","id":73765346,"user":{"login":"EToreo","id":1248716,"avatar_url":"https://avatars.githubusercontent.com/u/1248716?v=3","gravatar_id":"","url":"https://api.github.com/users/EToreo","html_url":"https://github.com/EToreo","followers_url":"https://api.github.com/users/EToreo/followers","following_url":"https://api.github.com/users/EToreo/following{/other_user}","gists_url":"https://api.github.com/users/EToreo/gists{/gist_id}","starred_url":"https://api.github.com/users/EToreo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EToreo/subscriptions","organizations_url":"https://api.github.com/users/EToreo/orgs","repos_url":"https://api.github.com/users/EToreo/repos","events_url":"https://api.github.com/users/EToreo/events{/privacy}","received_events_url":"https://api.github.com/users/EToreo/received_events","type":"User","site_admin":false},"created_at":"2015-02-10T19:25:34Z","updated_at":"2015-02-10T19:25:34Z","body":"Note that in the log `options.transaction =  false`, never `true`.\r\n\r\nLog:\r\n```text\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nModel.prototype.findOrCreate\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 1\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 1\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 1\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 1\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 2\r\nModel.prototype.findOrCreate - create...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 2\r\nModel.prototype.findOrCreate - create...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 2\r\nModel.prototype.findOrCreate - create...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 2\r\nModel.prototype.findOrCreate - create...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 1\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nModel.prototype.findOrCreate - then 2\r\nModel.prototype.findOrCreate - create...\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - then\r\nSequelize.prototype.query - query.run...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\nSequelize.prototype.query - inside query.run\r\n        options.transaction =  false\r\nSequelize.prototype.query - Promise.resolve...\r\n```\r\n\r\nCode:\r\n```javascript\r\n\r\nconsole.log('Sequelize.prototype.query - Promise.resolve...');\r\n    return Promise.resolve(\r\n      options.transaction ? options.transaction.connection : self.connectionManager.getConnection(options)\r\n    ).then(function (connection) {\r\nconsole.log('Sequelize.prototype.query - then');\r\n      var query = new self.dialect.Query(connection, self, callee, options);\r\nconsole.log('Sequelize.prototype.query - query.run...');\r\n      return query.run(sql).finally(function() {\r\nconsole.log('Sequelize.prototype.query - inside query.run');\r\nconsole.log('\\toptions.transaction = ', options.transaction == null);\r\n        if (options.transaction) return;\r\nconsole.log('\\tself.connectionManager.releaseConnection');\r\n        return self.connectionManager.releaseConnection(connection);\r\n      });\r\n    });\r\n  };\r\n```"}}