PDA

View Full Version : Events get lost or overwritten


rottenronny
12-28-2009, 09:09 AM
This is a very technical post that takes a stab at what might be causing the problem...

During the last couple of weeks, I have noticed many occurrences where an action whose result was displayed on my side is subsequently lost, as if it never happened. Two examples:

I bank my money, it says 'success', I continue with another thing, and then the money reappears outside of the bank! Usually, this happens when someone else has attacked me. I realize that this situation can happen and when it is handled correctly, the response from the server indicates a failure and offers to put the new remaining balance into the bank. So, it is a bug if the server responds with success and shows $0 not deposited and then on a subsequent action puts it all back out there again as if it never happened.

A similar thing happens occasionally when you race someone, win money, it shows a big win and the cash balance goes up. Then, immediately thereafter, someone else races you, you show a small loss on the screen, but you lose everything from the previous win as well -- as if the previous win didn't happen.

In both cases, someone racing you caused a CONFIRMED action to be lost completely. It looks to me to be a multithreading issue or database replication issue .Two different servers (or server threads) take the current state and start handling an event: one from me and one from someone else racing me. Both threads start with the same state, I get my response, the database is written to, and the other race is handled by the other thread and the database is written to but that result is based on data that does not take the results of my action. In other words, two threads read the state, change the state and write a new state, with the second write trampling on the first write. In software-speak, this is a classic parallelism issue -- or, more specifically, a lack of "critical section" issue.