{"action":"created","issue":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/2776","repository_url":"https://api.github.com/repos/Sylius/Sylius","labels_url":"https://api.github.com/repos/Sylius/Sylius/issues/2776/labels{/name}","comments_url":"https://api.github.com/repos/Sylius/Sylius/issues/2776/comments","events_url":"https://api.github.com/repos/Sylius/Sylius/issues/2776/events","html_url":"https://github.com/Sylius/Sylius/issues/2776","id":80498401,"number":2776,"title":"Race conditions in inventory tracking, order, payment status...","user":{"login":"umpirsky","id":208957,"avatar_url":"https://avatars.githubusercontent.com/u/208957?v=3","gravatar_id":"","url":"https://api.github.com/users/umpirsky","html_url":"https://github.com/umpirsky","followers_url":"https://api.github.com/users/umpirsky/followers","following_url":"https://api.github.com/users/umpirsky/following{/other_user}","gists_url":"https://api.github.com/users/umpirsky/gists{/gist_id}","starred_url":"https://api.github.com/users/umpirsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/umpirsky/subscriptions","organizations_url":"https://api.github.com/users/umpirsky/orgs","repos_url":"https://api.github.com/users/umpirsky/repos","events_url":"https://api.github.com/users/umpirsky/events{/privacy}","received_events_url":"https://api.github.com/users/umpirsky/received_events","type":"User","site_admin":false},"labels":[{"id":159079977,"url":"https://api.github.com/repos/Sylius/Sylius/labels/Blocker","name":"Blocker","color":"a80000","default":false},{"id":182603,"url":"https://api.github.com/repos/Sylius/Sylius/labels/Bug","name":"Bug","color":"e10c02","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2015-05-25T11:07:42Z","updated_at":"2016-11-18T07:32:00Z","closed_at":null,"body":"We are getting inventory deducted at exact same second, where one of them should have already been sold out. Looks like availability is checked at the same time, saying item is in stock, and then deducted twice by two different orders/users.\n\nSimilar thing happens with order status being changed to \"confirmed\" and \"pending\" at the same time, and then one override another. We sometimes see confirmed order with \"pending\" status, according to the change log they was changed at the same second.\n\n@pjedrzejewski Are you aware of this issue? Can you suggest ways to fix it, I am interested to contribute it to Sylius. I was even thinking of MySQL row locking. :)\n"},"comment":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/comments/261467027","html_url":"https://github.com/Sylius/Sylius/issues/2776#issuecomment-261467027","issue_url":"https://api.github.com/repos/Sylius/Sylius/issues/2776","id":261467027,"user":{"login":"psihius","id":3097957,"avatar_url":"https://avatars.githubusercontent.com/u/3097957?v=3","gravatar_id":"","url":"https://api.github.com/users/psihius","html_url":"https://github.com/psihius","followers_url":"https://api.github.com/users/psihius/followers","following_url":"https://api.github.com/users/psihius/following{/other_user}","gists_url":"https://api.github.com/users/psihius/gists{/gist_id}","starred_url":"https://api.github.com/users/psihius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psihius/subscriptions","organizations_url":"https://api.github.com/users/psihius/orgs","repos_url":"https://api.github.com/users/psihius/repos","events_url":"https://api.github.com/users/psihius/events{/privacy}","received_events_url":"https://api.github.com/users/psihius/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T07:32:00Z","updated_at":"2016-11-18T07:32:00Z","body":"I have a suggestion that I used when dealing with money and balances.\r\nIn my experience dealing with money for 4 years is that whatever locking mechanic you try to use, it goes wrong anyway. The moment you have more than one web server, your only source to do locking is the database. Some have good tools for that, some not so. Some can lock a row, others can lock a table. In any case, I had dealt with too many deadlock situations in MySQL due - probably when PHP scripts died due to fatal error or some other problem and your database left with the lock active.\r\nWhat I ended up doing, is using double read strategy in my code. Start a transaction, check the values, do the operation, re-read the value and check that it didn't go below 0. If everything is okay - commit. If not - rollback the whole thing and throw an error. This way you are guaranteed to catch the moment you go into negative.\r\nGood thing a saw this, because if I launch the shop I develop with this not fixed, 500 unit drift from the above comment would be a mild case compared to my problems :("}}
{"actor":{"display_login":"psihius"}}