Getting AUTH_ERROR When Connecting Very Quickly After Disconnecting (WinRT)

0 votes
Hello,

I am writing an application for Windows Runtime (Windows Phone 8.1 and Windows 8.1) using the AppWarp SDK and I am having trouble trying to allow players to leave a game and join another one very quickly. Basically I have a leave button which disconnects from AppWarp and then goes back to the main page where they can immediately press join again to connect and find a random game but after connecting, joinining a game, and disconnecting a few times in rapid succession I always get an AUTH_ERROR when I try to connect again and I have to wait for the Recovery Time set in my WarpClient before I can connect again. I am making sure that I receive the onDisconnectDone callback with a success code before I connect again as I have been printing every time I connect and disconnect and similar to this (though the exact number of times I can connect without error varies it is usually around 3-4 disconnects before it errors):

- Connecting...

- Connected Successfully

- Disconnected Successfully

- Connecting...

- Connected Successfully

- Disconnected Successfully

- Connecting...

- AUTH_ERROR

Since I have to wait for the recovery time before I can connect again it seems that for some reason my session is not ending properly when I disconnect and this is causing it to fail when I connect again. Every time I do connect successfully I also call GetRoomWithProperties then GetLiveRoomInfo then SubscribeRoom then JoinRoom and on the same room ID every time in case that helps pinpoint where the problem might be happening.

Also, when I disconnect, the other players in the room are getting an onUserLeftRoom notification as they should except the last time disconnect before the AUTH_ERROR occurs they get onUserPaused instead for some reason even though I am calling disconnect.

Lastly, the reason code I receive in the onConnectDone callback for the AUTH_ERROR is always Waiting for Paused User.
asked Dec 30, 2014 in AppWarp by feraask (45 points)
edited Dec 30, 2014 by feraask
Hi Feraask,
We have updated our WinRT SDK. In newer version we have solved this bug. You can get the new version here https://github.com/shephertz/AppWarpWinRT/tree/master/v_1.10.1

1 Answer

0 votes
Hi Feraask,

For switching across rooms, you don't need to end the seesion everytime you wish to leave  a room and join another one.So don't disconnect each time you wish to leave a room.Just use the LeaveRoom API and then the JoinRoom API for joining a new room.

At our side the connect and disconnect APIs when called simultaneously are working fine.There must be some minute problem with your code.Ideally you should not be getting the AUTH_ERROR.

 

Thanks

Kanika Mittal

AppWarp Team
answered Dec 30, 2014 by kanika mittal (50 points)
I have been doing a lot of testing and I just can't seem to figure this out. I know I don't need to disconnect to switch rooms but I am not always going to be switching rooms, I disconnect once the user ends a game and they could go do other things or they could start playing again right away. They can also switch directly from one room to another and in that case I don't disconnect. If I used the LeaveRoom API then I have to call LeaveRoom and Unsubscribe to fully leave a room correct? thus it just makes it easier (and less prone to issues hopefully since it only requires the internet for one api call) to disconnect rather than calling two both LeaveRoom and Unsubscribe. Or does LeaveRoom automatically unsubscribe the player?

Did you make sure when you did your testing to have a recovery allowance set (I have mine set to 30 seconds)? Because if I turn this off by setting the recovery allowance to 0 it works fine so it definitely seems like the session is not ending properly even though it is returning a disconnected successfully response code.

I am even calling WarpClient.GetInstance().GetConnectionState() before connecting and making sure that it is disconnected before continuing and calling connect again and I know it is not calling it twice as I have Debug.WriteLine("Connecting with username: " + username) right before I call connect and this is only showing up once.

Also the fact that the other users are getting a player paused but my local client says the state is disconnected means that something in the API between my local WarpClient instance and the server is not getting communicated properly and the server is keeping the session alive for some reason.

I have also set the debugger to break at any type of exception and nothing is happening at all. I also have a Debug.WriteLine statement when I get OnDisconnectDone and I am getting a clean disconnect but for some reason the other players and the server is seeing it as a connection error recoverable and keeping the session alive.

Lastly, I am using AppWarpWinRT v1.6.7, is there a newer version available?
Hi,

It is upto you if you wish to use the LeaveRoom and UnsubscribeRoom APIs or not.The AppWarp SDKs do not unsubsribe a room automatically when you leave the room.

We have verified that the RecoverConnection API is not creating any problem while disconnecting or connecting.It's working fine at our end whatever recovery time we set (between 0 and 120).

The latest version of the SDK is v_1.10.Try using it and let us know if the problem still persists.If not the complete code, you may share some code snippet with us where you are facing the problem.
I have tried updating to the latest SDK version and I still have the problem, although it is occurring less often now. It is extremely confusing as I am checking the ConnectionState right before calling connect and it is set to disconnected yet the AUTH_ERROR response I get has a reason code of Waiting_for_paused_user which means that my session for some reason is not actually disconnected. Similarly, the majority of the time when I disconnect the other players get the onUserLeftRoom but the time it stops working is when I call disconnect and the other players get a onUserPaused instead but my Connection Listener does not get any Connection_Error_recoverable callback and I still get onDisconectDone with a Success code.

The way I have my code structured is this:
- on the MainPage the user clicks join random game which does the following steps: 1) connect to appwarp, 2) get all the rooms, 3) pick a random one, 4) get the live room info, 5) Join and Subscribe to the room, 6) Load a lot of local values based on the info, 7) Navigate to the game page.
- Then on the GamePage I add a handler to handle the Hardware Back Button Press so that it shows a prompt asking if the user is sure they want to leave the game room. If they press yes then the following happens: 1) Clear all the local values about the room, 2) disconnect from appwarp, 3) Navigate back to the MainPage

So what I am doing just for testing is clicking join random game and then as soon as the app navigates to the GamePage I click the back button and press leave room, then repeat as quickly as possible as if a user just wants to keep joining random games and leaving them as quickly as possible. Now during this time there is always 1 or more other players who just stay in the room and get notified when the one player joins and leaves over and over.

As I mentioned I have setup print statements at almost every step and here is the output:
Connecting to AppWarp
Connected to AppWarp successfully
Finding Room
Getting room info for ID: 2041628056
Joining Game
clearing game data
Disconnecting from AppWarp
Disconnected from AppWarp Successfully
leave room complete
Connecting to AppWarp
Connected to AppWarp successfully
Finding Room
Getting room info for ID: 2041628056
Joining Game
clearing game data
Disconnecting from AppWarp
Disconnected from AppWarp Successfully
leave room complete
Connecting to AppWarp
Connected to AppWarp successfully
Finding Room
Getting room info for ID: 2041628056
Joining Game
clearing game data
Disconnecting from AppWarp
Disconnected from AppWarp Successfully
leave room complete
... repeated many times until:
Connecting to AppWarp
AUTH_ERROR Reason Code: Waiting for Paused User (21)

I also have it set to print out whenever any sort of connection error occurs not just AUTH_ERROR and I am not getting Conection_error_recoverable ever nor am I ever calling recover connection so I do not know why the session is not being ended. I don't know if any of this helps I'm just trying to provide more information about my setup.
We have tested our SDK and it's working properly.We are unable to reproduce the problem you have mentioned.I recommend you to share the source code of your application with us at support@shephertz.com
Alright so I wrote a very simple test application which exhibits the issues I have been having. It requires 2 devices (which I call device1 and device2), the instructions to use it are as follows:
1) Replace the apiKey and secretKey values in AppServices.cs
2) Run the application on both devices
3) On each device type a unique username in the input text box and hit connect
4) On the device1 just click join room with the input text box being empty (this will create and join a new room and print out the room ID)
5) On the device2 type the room ID that was printed out on the device1 and click join.
6) Once both users are joined in the same room disable the network connection on device2 and re-enable it very quickly (this is just to force the connection to drop)
7) Wait for device2 to recover the connection which will take about 15 seconds
8) Once device2 has recovered look at the printed messages and notice that it received the onUserResumed callback when it shouldn't, it also received that callback when the connection state was still set to recovering and then it receives the Recovered Successfully.
8) Now click disconnect on device2
9) If you look at the device1 it will sometimes say that the player paused instead of left the room when they disconnected (usually this happens after 2+ times if you leave device1 connected and in the same room and then re-run the app on device2 and join and disable the network and recover and then disconnect again).

Also, if you try to connect again on device2 you will start receiving each callback twice instead of just once. and then if you disconnect again and connect again you will start receiving 3 of the same callbacks on every call and so on...

Here is an example of the output from each device:

device1:
Connecting with username: device1
Connected Successfully!
joining & subscribing to room: 563244
joined room: 563244
subscribed to room: 563244
device2 paused
device2 resumed
my connection state: 0
device2 paused

device2:
Connecting with username: device2
Connected Successfully!
creating a new room...
created room id: 563244
joining & subscribing to room...
joined room: 563244
subscribed to room: 563244
device1 joined room
Connection error recoverable occured. waiting 15 seconds to recover...
recovering...
device2 resumed
my connection state: 4
Connection Recovered!
Disconnecting...
Disconnect Successfully!

Here is the code: https://bitbucket.org/feraask/appwarptest_winrt/get/42d7c8a03812.zip
Hi Feraask,

Thank you for sharing your project with us.
There are two major problems in your code due to which you are facing the above problems.

1. You need not create a static variable for storing the WarpClient instance in your AppServices.cs class.AppWarp itself operates on a singleton object of WarpClient.So for each session, there exists only one instance of WarpClient which stores all the required details.So you need not create any local class object to store it.Instead you should use the GetInstance() API.Syntax :
WarpClient.GetInstance();

2. You are Initializing the WarpClient object everytime you click on Connect button which is wrong usage of the Initialize API.Ideally, you should call the Initialize() method only once for a complete session.You can check the connectButton_Click() method,WarpClient.initialize(AppServices.apiKey, AppServices.secretKey); statement gives an error when you call Initialize eventhough an instance of WarpClient already exists.Because of this only you are getting the callbacks repeatedly.

As far as the OnUserResumed callback is concerned,you were right it is being called when a user recovers from a lost connection.This is no error and if you don't want to get this you can handle it your way.Inside the onUserResumed callback in the NotificationListener class in your code,just check if the username received is same asyour own username.If yes, return the control back to where it was.

Thanx
Okay thanks for those clarifications. I whipped together this basic app really quickly just to test the connection issues so I totally forgot I was calling initialize and setting the listeners multiple times that makes sense why I am getting the callbacks so that is fine (it is funny though because I made neither of the mistakes you mentioned with the code I originally reported the problem with lol). I have gone ahead and updated the code to fix the issues you mentioned but I am still having the problems I originally talked about:

1. When the OnUserResumed notification is received on device2 after it has lost connection and is trying to recover the connection state is still set to Recovering (i.e. I am getting the OnUserResumed notification before I get the SUCCESS_RECOVERED callback) so if I try to call any other API's functionality inside the OnUserResumed notification it always fails. Now this can easily be fixed by waiting inside the OnUserResumed until the connection state is set to connected but shouldn't the OnUserResumed only be called once the connection state has been set to Connected and the connection is fully restored?

2. If you connect and join a room and then lose connection and recover then disconnect and then connect and join that same room again then disconnect all with device2 while keeping device1 connected and joined in the same room the entire time, when you Disconnect() device2 the 2nd time device1 will get an onUserPaused notification for device2 instead of onUserLeftRoom and if you try to connect device2 again you will get an AUTH_ERROR because the session is still alive for some reason even though I call Disconnect(). Am I doing something wrong here that my disconnects are not ending the session properly or is there a bug?

Here is the new code:
https://bitbucket.org/feraask/appwarptest_winrt/get/cf807fbaa536.zip
Hi Feraask,

Thank you for your suggestions about the SDK,we will discuss it with our team and make the changes if required.
We tested your code for the problem you mentioned but the code is working completely fine.We could not reproduce the problem.It's quite possible that there is some network problem with the network you are using on device 2 due to which you are  unable to disconnect or recover connection.

Thanks
Okay so I have tested this on many different networks and different combinations of using the emulator and a real device (Nokia Lumia 1020) and they all exhibit the same connection resiliency issues where I call Disconnect and get a successful callback with no errors but the session is not actually ended. This really makes me believe that it cannot be a network issue, and in any case if it was a network issue the AppWarp SDK should not return disconnect success. I have even written a test application targeting Windows Phone 8 silverlight rather than Windows Phone 8.1/Windows 8.1 (using WinRT not silverlight) and the Windows Phone 8 version has no problems and works correctly, so there is definitely an issue in the WinRT version of the AppWarp SDK. Here is the Windows Phone 8 silverlight version for reference, it is almost identical to the WinRT version:
https://bitbucket.org/feraask/appwarptest_wp8/get/f6b085f44884.zip

Is there anything else you guys can do to help me?
Hi Feraask,
Your project is working fine again at our end.
Please tell us the server you are runing your app on.So that we can try running it on the same and test.
I'm not sure which server I am using, how can I determine this?

Also, would you mind posting some screenshots of you running my code and going through a connect and join on device1 and a connect, join, recover, disconnect, and connect again on device 2 (like I described earlier)? This way I can see the output from device1 and device2 and make sure you are testing it the same way I am and doing the same steps.

I just can't seem to figure out a reason why this disconnect issue is happening since it works fine on the Windows Phone 8 version but the WinRT version doesn't seem to always end sessions properly.

By the way I just want to say thanks for working with me so much on this, I really do appreciate your patience and help, I just want to get to the bottom of this issue as soon as possible.
While creating your App from the AppHQ dashboard, you get an option to choose the zone.If you did not change it then by default your zone is US.

Please check the screenshots at
http://cdn.shephertz.com/repository/files/19b5d3409bf22f86f17dc1cdd52c5c31f3dececcf7d139c09ed78ab99e75f6e1/ba3db9c65a8e978ec8b2b82eeeb9e4f86b31976e/device_screenshot.png

and

http://cdn.shephertz.com/repository/files/19b5d3409bf22f86f17dc1cdd52c5c31f3dececcf7d139c09ed78ab99e75f6e1/4c8cff842381b9c2847ca79ab53485c3f85563ed/emulator_screenshot.png

I'm repeating the same steps repeatedly on device2 and it's working fine.
It's our pleasure to help you use our products in the best possible ways. :)

Thanks
That's what I thought but I wasn't sure, yes I kept the default server of U.S.

It looks like you posted screenshots from the Windows Phone 8 version rather than the WinRT version of the code that I sent you. The Windows Phone 8 version works fine on my end as well it is only the WinRT version that I am having problems (I know it says WinRT at the top of the Page but I forgot to update the name since I copied most of the code to make the Windows Phone 8 version from the WinRT version, though I have fixed this now in the links below). Could you please run the WinRT version that I sent you instead with the same steps and post the screenshots?

Here are the links again

WinRT: https://bitbucket.org/feraask/appwarptest_winrt/get/d0392a25757b.zip

WP8: https://bitbucket.org/feraask/appwarptest_wp8/get/5b4809443b78.zip

I have also created screen shots showing an example of the problem I am having which you can find here:
https://bitbucket.org/feraask/appwarptest_winrt/downloads/AppWarpWinRT%20Connection%20Error%20Example.zip

What I did in those examples is the following:
device1 (emulator 8.1 WVGA 4 inch 512MB) - Connect, Join Room already created by device2, wait
device 2 (Nokia Lumia 1020 running in debug mode connected to visual studio professional 2013) - Connect, Create/Join room, turn off Wi-Fi and wait for connection error to happen, turn on Wi-Fi and wait for connection to recover, disconnect, connect again, re-join the same room, turn off Wi-Fi and wait for connection error, turn on Wi-FI and wait for recover, disconnect, try to connect again.

You can see that after device2 resumes the second time and calls disconnect, it actually doesn't end the session and device1 shows that device2 paused instead of left room and when I try to connect again with device2 I get an AUTH_ERROR that there is already a paused user.

I have also tried having device1 be the Lumia 1020 and device2 be the emulator and the same thing happens (though not always the same amount of connect, recover, disconnect times it eventually happens). I have tried them both outside of debug mode and the same thing happens as well. I have tried them on different Wi-Fi networks or the emulator on Wi-Fi and the Lumia on Cellular Data and it still has the issue.

Lastly, I have also gotten the error to happen just by connecting and disconnecting multiple times in succession as you can see here (though again I can't seem to make it happen every time doing the exact same number of connects and disconnects, but it always happens eventually):
https://bitbucket.org/feraask/appwarptest_winrt/downloads/AppWarpWinRT%20Connect-Disconnect%20Error%20Example.zip
You are addressing two problems here:

1) connecting->joining a room->recover connection->disconnect repeatedly.

This one is again working fine when tested for WinRT sample shared by you.
please find the screenshots below:
http://cdn.shephertz.com/repository/files/32dd7e0b3fab55b9d88ec293e289afb6258e2b12b9841d30adf6fb3df25ece71/e16c1febff03585b55dc2d2aabedb965a39f3067/emualtor_1.png
http://cdn.shephertz.com/repository/files/32dd7e0b3fab55b9d88ec293e289afb6258e2b12b9841d30adf6fb3df25ece71/5c4e8996ead756fe16e73adba6359a763e130154/emulator_2.png
http://cdn.shephertz.com/repository/files/32dd7e0b3fab55b9d88ec293e289afb6258e2b12b9841d30adf6fb3df25ece71/fec60b14f12534046fcd7d837a4d4bf6577bca9e/device_1.png
http://cdn.shephertz.com/repository/files/32dd7e0b3fab55b9d88ec293e289afb6258e2b12b9841d30adf6fb3df25ece71/5a229c9a40f15e9994a8b370e1d0a4ac3bcad9da/device_2.png
http://cdn.shephertz.com/repository/files/32dd7e0b3fab55b9d88ec293e289afb6258e2b12b9841d30adf6fb3df25ece71/568355ac86116e559bd6acc890b88f3253e0f021/device_3.png

2) connect->disconnect->connect->disconnect repeatedly.

We have been able to reproduce this problem this time and we are working on it.Although it occurs after a long interval while continuously calling connect and disconnect APIs in succession,but the problem exists.Infact the first problem you are facing may also be a result of this only.
We will soon get back to you with a solution for this.

Note : In your WinRT sample,in AppServices.cs class you have made the onConnectDone nad onDisonnectDone callbacks as async which is creating threading problem.You don't need to make these methods async.
Okay great please let me know when you find a solution to the problem (is there any ETA?). I believe that both of them are related to the same issue most likely since I can't make it happen every single time consistently.

Secondly, the reason I made them async was so that I could call Dispatcher.RunAsync() in the PrintMessage() method and print messages to the UI as this must be done from the main UI thread and can't be done directly from the callback as it will cause an exception. Is there another way I can print to the UI thread from the callbacks without making them async?
Hello Feraask,

While testing your WinRT sample for the AUTH_ERROR, we came across threading issues while calling connect and disconnect repeatedly in succession.So we thought that the problem might lie within the AppWarp SDK.But when we thoroughly went through your sample again, we found that the threading issue is all because you are using async everywhere in callbacks which is causing the delay in task completion to give undesirable results in the calbacks.In AppWarp SDKs, we have taken special care to handle such threading issues.

So, just for updating your UI, you do not to fiddle with the AppWarp RequestListener callbacks.
You can very well do it using the CoreDispatcher class like we have done in our sample app for AppWarp_WinRT.Please go through the sample https://github.com/shephertz/AppWarpWinRT.This will help you update your UI without making the callbacks as async and will also do away with the threading problem in your app.

Thanks
Okay so I have replaced all the async and await calls in my code with .Wait() similar to how the sample you provided does and I even removed the async from the Connect and Disconnect button click methods and I am still having the same connect disconnect issue as before. If I just keep connecting and disconnecting repeatedly in succession I still get the AUTH_ERROR waiting for paused user. Here is the new version of my code:
https://bitbucket.org/feraask/appwarptest_winrt/get/b55b1a8df6f3.zip

I have also tested this in the sample you have provided and I have the same issue. All I did was add WarpClient.setRecoveryAllowance(60) in the constructor for the MainPage and commented out these lines in the onConnectDone AUTH_ERROR callback because they would cause exceptions:

int sessionID = (int)DBManager.getDBData("SessionID");
Debug.WriteLine("Auth Error for paused user " + sessionID);
WarpClient.GetInstance().RecoverConnectionWithSessioId(sessionID, "rahul");

and the same issue still happens, here is a screenshot:
https://bitbucket.org/feraask/appwarptest_winrt/downloads/AppWarpWinRT%20Connection%20Error%20-%20ShepHertz%20Sample.png

Am I doing something wrong?
Is there any update on a possible fix for this issue?
Hi Feraask,

We are currently working on the issue and will get back to you as soon as it gets fixed up.

Thanks
Do you have any progress updates on how the fix for this issue is coming along?
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
...