{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/9302","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/9302/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/9302/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/9302/events","html_url":"https://github.com/sequelize/sequelize/issues/9302","id":314312811,"number":9302,"title":"Sequelize SQLite Busy Error when Initiated by multiple Users","user":{"login":"LaserStony","id":34425251,"avatar_url":"https://avatars0.githubusercontent.com/u/34425251?v=4","gravatar_id":"","url":"https://api.github.com/users/LaserStony","html_url":"https://github.com/LaserStony","followers_url":"https://api.github.com/users/LaserStony/followers","following_url":"https://api.github.com/users/LaserStony/following{/other_user}","gists_url":"https://api.github.com/users/LaserStony/gists{/gist_id}","starred_url":"https://api.github.com/users/LaserStony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LaserStony/subscriptions","organizations_url":"https://api.github.com/users/LaserStony/orgs","repos_url":"https://api.github.com/users/LaserStony/repos","events_url":"https://api.github.com/users/LaserStony/events{/privacy}","received_events_url":"https://api.github.com/users/LaserStony/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-04-14T09:00:26Z","updated_at":"2018-04-14T10:26:09Z","closed_at":null,"author_association":"NONE","body":"## What are you doing?\r\nI am trying to handle multiple user calls to create or Fetch Data. But When a user calls the fetch function while another user called a create function, the SQLite Busy Error pops in the terminal.\r\n```js\r\nawait  client.db.Project.findOrCreate({\r\n\t\t\t\twhere: {\r\n\t\t\t\t\tname: projectTitle,\r\n\t\t\t\t\tabbr: projectAbbr,\r\n\t\t\t\t\tstatusAbbr: Status\r\n\t\t\t\t}\r\n\t\t\t}).spread((prjct, created) => {\r\n\t\t\t\t//project.setStatus();\r\n\t\t\t\tif (!created) {\r\n\t\t\t\t\tclient.db.currentGuild.getProjects({where: {abbr: prjct.abbr}}).then(prjcts => {\r\n\t\t\t\t\t\tif (prjcts.length === 0) {\r\n\t\t\t\t\t\t\tclient.db.currentGuild.createProject({\r\n\t\t\t\t\t\t\t\tname: prjct.name,\r\n\t\t\t\t\t\t\t\tabbr: prjct.abbr,\r\n\t\t\t\t\t\t\t\tstatusAbbr: prjct.statusAbbr\r\n\t\t\t\t\t\t\t}).then(prjcct => {\r\n\t\t\t\t\t\t\t\tclient.db.Status.findOne({where: {abbr: Status}}).then(stat => {\r\n\t\t\t\t\t\t\t\t\tprjcct.setStatuses([stat]);\r\n\t\t\t\t\t\t\t\t\t//console.log(stat);\r\n\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t\t//\r\n\t\t\t\t\t\t\t\tclient.helper.addMsgToDel(\"Done!\");\r\n\t\t\t\t\t\t\t\tmsg.channel.send(\"Done!\");\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t//client.helper.addMsgToDel(\"Project \");\r\n\t\t\t\t\t\t\tmsg.channel.send(`A Project With ABBR => **${prjct.abbr.toUpperCase()}** already Exist. Named as => **${prjct.name}**`).then(mssssg => {\r\n\t\t\t\t\t\t\t\tsetTimeout(function () {\r\n\t\t\t\t\t\t\t\t\tmssssg.delete();\r\n\t\t\t\t\t\t\t\t}, 7000);\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tsetTimeout(function () {\r\n\t\t\t\t\tmsg.delete();\r\n\t\t\t\t}, 3000);\r\n\t\t\t});\r\n```\r\n\r\n## What do you expect to happen?\r\nI expected the code to execute without any errors.\r\n\r\n## What is actually happening?\r\nI am getting the SQLite Busy error when multiple calls are made to the Database. Is there Any Way to resolve this?\r\n\r\n\r\n__Dialect:__ sqlite\r\n__Dialect version:__ 4.0.0\r\n__Database version:__ (Don't know what this is)\r\n__Sequelize version:__ 4.37.6\r\n__Tested with latest release:__ No (If yes, specify that version)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/381319478","html_url":"https://github.com/sequelize/sequelize/issues/9302#issuecomment-381319478","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/9302","id":381319478,"user":{"login":"sushantdhiman","id":9989487,"avatar_url":"https://avatars1.githubusercontent.com/u/9989487?v=4","gravatar_id":"","url":"https://api.github.com/users/sushantdhiman","html_url":"https://github.com/sushantdhiman","followers_url":"https://api.github.com/users/sushantdhiman/followers","following_url":"https://api.github.com/users/sushantdhiman/following{/other_user}","gists_url":"https://api.github.com/users/sushantdhiman/gists{/gist_id}","starred_url":"https://api.github.com/users/sushantdhiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sushantdhiman/subscriptions","organizations_url":"https://api.github.com/users/sushantdhiman/orgs","repos_url":"https://api.github.com/users/sushantdhiman/repos","events_url":"https://api.github.com/users/sushantdhiman/events{/privacy}","received_events_url":"https://api.github.com/users/sushantdhiman/received_events","type":"User","site_admin":false},"created_at":"2018-04-14T10:26:09Z","updated_at":"2018-04-14T10:26:09Z","author_association":"OWNER","body":"Transactions are used whenever you want to make some changes to database that your can either commit or rollback as a whole.\r\n\r\nSuppose a user is registering by Facebook, you first need to create a row in `User` table then create another row in `Oauth` table. What happens if your connection dropped between these two operations? In situations like this you use transactions, to either insert those two rows or nothing at all. This is just an example of transaction use case, there is lot more to them.\r\n\r\n> Do they work same as async to execute code sequentially?\r\n\r\nFor SQLite, only one transaction at a time is supported for entire server (DB instance to be percise). Even if you are using async or other module, if another user is able to trigger another transaction you will get LOCK / BUSY error. A general solution is to retry in such cases."}}
{"actor":{"display_login":"sushantdhiman"}}