race condition in word junkie multiplayer example

0 votes
Hi,

I have a question regarding the matchmaking for the turn-based multiplayer of App42. If I understand the word junkie example [1] correctly, then matchmaking with random players works something like this:

1. retrieve list of files from random_stack collection

2. choose random file

3. random file contains second player id for this game

4. remove random file from collection

5. start playing with player

Isn't it very likely that a race condition happens between choosing a random player and removing the random player from the collection? A third player could randomly get the same file in step 2 and start a game with this randomly drawn player. However, the randomly drawn player will already be busy with the player, who asked him first.

Does the server throw a message that the file already was deleted by another player. If I can catch this, I could try to select another random player. Is the remove file operation implemented in a way that if two players try to delete the same file at the same time, only one player actually is successful and the other one is notified that he failed so that he can try another random file?

Best,

Markus

[1] http://api.shephertz.com/app42-dev/ebook-turn-based-games.php
asked Jan 30, 2015 in App42 Cloud API-BaaS by tatze82 (21 points)
edited Jan 31, 2015 by tatze82

1 Answer

0 votes
 
Best answer

Hi Markus,

I completely agree with you. In the current scenario, there is a chance of race condition and we have kept it intentionally. 

But the developer can avoid it depending on the game requirement.

For your second question, yes, server throws an exception when you are trying to delete a document which is already deleted. If simultaneous requests come to server to delete the same document then only one will get success response and others will get App42Exception.

Let us know if you have further queries.

Thanks.

answered Feb 1, 2015 by rajeev.etc (1,660 points)
selected Feb 1, 2015 by tatze82
Thank you for the clarification!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...