Forum C# UserJoined Race Condition

UserJoined Race Condition

Postby mechanicallyseparatedgames » September 19th, 2014, 8:37 am

Henrik or other Admin,

I started up 3 clients in rapid succession on my machine and they all tried to join the same matchmaking room at nearly the same time close to each other. I repeated this many times for testing purposes, and during one of the tests, I got two players being assigned the same player.Id, even though their player.ConnectUserId's are different. This shouldn't be possible right? Do I need to check for this condition in UserJoined()?

Code: Select all
=====[  Room Started: MatchMakingRoom  ]===
>User 69b890f7-284e-4b11-8bb9-d34f32089946 (1): Joined game
>User 621a27a1-d822-4628-b17a-c43f9d2b026c (1): Joined game
>User 60b286c6-f0bd-41dc-8217-05049a3d7105 (2): Joined game


My client connect code was pretty standard, unless I overlooked something. All variables were assigned appropriately.

Code: Select all
      client.Multiplayer.CreateJoinRoom(
         roomID,               
         roomType,
         isVisibleInLobby,
         null,
         null,
         delegate(Connection connection)
         {
            playerIOConnection = connection;
            playerIOConnection.OnMessage += AddToServerMessagesQueue;
         },
         delegate(PlayerIOError error)
         {
            Debug.LogError(error.ToString());
         }
      );


Also on the development server window the top player kept flickering on each screen update. I assume it's writing the first (1) and quickly rewriting with the second (1), since I only see the data for the second (1).

I used Secure Basic Authentication with a hash, if that matters at all.
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am

Re: UserJoined Race Condition

Postby Henrik » September 19th, 2014, 7:48 pm

Thanks, we'll take a look and try to replicate this issue.

Was it a service-room, or a regular room that you joined?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: UserJoined Race Condition

Postby mechanicallyseparatedgames » September 20th, 2014, 4:10 am

I created a regular room. During each test I would launch 3 clients in rapid succession and once I saw that all 3 had joined the matchmaking server room, I would kill the clients, closing the room in every case.

I tried to reproduce the error after I posted initially, but haven't seen it again. I may try testing again launching more clients at the same time and see if larger numbers makes it easier to force the problem again.

FWIW, I am creating standalone clients on my PC with Unity. So they have all the same IP address when trying to connect to the server. And they are all connecting to the same development server port. The server is running locally on my PC.
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am

Re: UserJoined Race Condition

Postby mechanicallyseparatedgames » September 22nd, 2014, 5:51 am

Henrik,

I encountered this problem again today. I'm also using Yahoo SDK 3.0.12, btw.

=====[ Room Started: MatchMakingRoom ]===
>User 70d924fb-5815-45ef-bf48-f84814848980 (1): Joined game
>User aa835fd5-bba4-49fc-b45d-da45639676a8 (1): Joined game

I've been launching 4 clients in rapid succession, and it was about 20-25 times that I did so before I saw this error. I haven't noticed it on my server that I set up for initialization or my game servers. I don't use player.Id in UserJoined() in either of those two room types, so it could just be that I haven't noticed it there. I guess I have to stop relying on player.Id being unique.

Even if I stop relying on it, the Development Server window cannot display both users, so it becomes less effective for debugging.
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am

Re: UserJoined Race Condition

Postby mechanicallyseparatedgames » September 24th, 2014, 7:47 am

Henrik,

I think this is how you reproduce the error:

Start up all clients one after another
Have all clients CreateJoinRoom on "Room-A"
Have them do something long enough to give you time to get all clients running
Disconnect the clients (I have the server do this)
Have all clients CreateJoinRoom on "Room-B", without regard for whether the first client actually finished creating the room
This will cause a race condition (which was poor design on my part); however, I'd expect the behavior to be that the second player would get a failed callback, not be assigned player.Id = 1 sometimes

I fixed my code to make sure the room was created first before allowing others to join, which seems to be the sensible thing to do anyway.
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am

Re: UserJoined Race Condition

Postby david » October 14th, 2014, 7:16 pm

Hi mechanicallyseparatedgames, I looked at our code and think that two Room objects are being created for the same RoomId.
Player1 -> RoomB -> RoomB_Object1: Player.Id = 1
Player2 -> RoomB -> RoomB_Object2: Player.Id = 1
Player3 -> RoomB -> RoomB_Object2: Player.Id = 2
Player4 -> RoomB -> RoomB_Object2: Player.Id = 3

This is why the very first players that join these 2 different room objects have the same PlayerId 1. From this point on only one Room object receives all players requesting Room-B.

In your code you can count that on a given Room (object) the Player.Id is unique. We are using "p.Id = Interlocked.Increment(ref playerInstanceId);" in our code, so there is no chance of 2 player being assigned the same Player.Id in the same room (object).

I have not been able to reproduce this problem. Could you please send me your test app that reproduces this problem? davidfig@yahoo-inc.com

Thank you.
david
 
Posts: 2
Joined: April 3rd, 2014, 5:46 pm

Re: UserJoined Race Condition

Postby mechanicallyseparatedgames » October 16th, 2014, 7:47 am

David,

Thank you for investigating. Unfortunately, I rewrote my code to more carefully join rooms as I mentioned and do not have version control, so I don't have a test app to send you. (Since rewriting I have not seen a problem.) However, my approach was just as I described in my previous posting.

As I also mentioned, the local development server dashboard showed all players in the same tab, except the 2 players with Player.Id = 1 were toggling back and forth. If two Room objects were being created as you said, would both Player.Id = 1 players fight to display in the same position, or would you see a second tab for the second game object?
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am


Return to C#