question

Gordon Graber avatar image
Gordon Graber asked

Unity - how to handle no response to login and other requests?

Hi All,

Every once in a while, due to my network or I'm not sure what, PlayFab never returns either success or error on login from Unity. It's like my request is just hanging there. This has happened since I started working with PlayFab.

If I stop the game and restart, it nearly always returns success, though on rare occasion it seems to repeat the pattern of waiting for success. I have never seen an error returned in this circumstance.

So I am looking for a general strategy. It seems obvious that PlayFab is waiting for some kind of return, though it seems impossible to determine determine why, .

The question is, how to structure Unity to test whether it has been too long, and either send the request again or inform the user that there has been some kind of network issue?

Should I run a coroutine timer, the checks some flags that are set on success or error, and if neither has been set within a given time to take some action, such as trying to login again?

What happens if the game is still trying to login, and I send the request a second time?

Does any of this make sense, or am way off in my understanding of what is going on and how to handle the problem?

unity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

>>Should I run a coroutine timer, the checks some flags that are set on success or error, and if neither has been set within a given time to take some action, such as trying to login again?

It should do the job.

>>What happens if the game is still trying to login, and I send the request a second time?

In the common scenario, each API will work independently. However, It depends on the last response to overwrite the session ticket/entity token. Since the user is accessing the same Player account. It won’t be a big deal.

Please also refer to Franklin’s answer in Request Timeout ignored in Unity sdk? - Playfab Community, and try to reproduce this issue when you have switched the setting to HttpWebRequest in Unity PlayFab Extension.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gordon Graber avatar image Gordon Graber commented ·

Thank you! Yes, I had read that post before submitting my question - didn't seem to make sense in my context.

But this has never been clear to me: Does PlayFab eventually return a timeout in the error condition, if a request does not return success or error in a given amount of time? If so, where is the timeout value set?

Back to my situation, if I run this timer and no response from the first login request is received by the time it expires, and then I run the method,

PlayFabClientAPI.LoginWith whatever

again, do I need to cancel the first call to that method? (how would I do that?)

I mean, wouldn't there be a problem if the 1st one returned success at a later time, after the 2nd (or even visa versa) ?

Or I'd have to flag that in my code and ignore which ever one returns success first tells my code to ignore anything else?

Or PlayFab handles canceling the first one for me?

Or what?

Thanks again for your help!

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Gordon Graber commented ·

PlayFab only support timeout monitoring in some specific APIs, like Cloud Script execution related API. However, it doesn't return a timeout HTTP code, and 200 code is returned because the HTTP communication between server and client is successful.

In another word, the timeout monitoring usually should be handled by the client. As I have mentioned above, if you switch the Request Type in the Unity Extension to HTTP Web Request, you are able to manually restrict the timeout limit for all APIs, When the login time out, "WebException: The operation has timed out." will be prompted in console.

Unity SDK won't be easy to add cancellation token for your API calls, If there is specific requriement, you may consider using C# SDK.

0 Likes 0 ·
Gordon Graber avatar image Gordon Graber commented ·

I made a typo in my response. This question should read:

Or I'd have to flag that in my code and whichever one returns success first tells my code to ignore anything else?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.