Idea

ezentertainmentstudio avatar image
ezentertainmentstudio suggested

PlayFab Login Timeout

Hi All,

We are using PlayFab integration for our Unity3D game. We have recently run into some unpleasant issues when attempting to have a user login to PlayFab (LoginWithAndroidDeviceIDRequest and/or LoginWithEmailAddressRequest) while having a poor internet connection.

Using step-by-step debugging we traced the issue to the PlayFabWWW class - Post coroutine.

The issue here is that the coroutine yields and waits for the WWW to complete. This leads to a timeout of 30 seconds or more which is unacceptable for users. Since Unity does not allow the WWW timeout to be changed, we did a bit of a hack inside the PlayFab coroutine:

private IEnumerator Post(WWW www, Action<string> wwwSuccessCallback, Action<string> wwwErrorCallback)
{
DateTime coroutineStart = DateTime.Now;
bool timeoutReached = false;
while(!timeoutReached && !www.isDone)
{
yield return null;
if((DateTime.Now - coroutineStart).Seconds >= 5)
{
timeoutReached = true;
}
}
if(timeoutReached)
{
www.Dispose();
wwwErrorCallback("Request timed out.");
yield break;
}
//... Rest of the code here ...
}

Using this method we reduced the timeout to a reasonable value.

We would like to know:

1. Do you think the above hack might cause issues? Our testing did not reveal any, but we don't really know all the use-cases for the Post coroutine.

2. Would it be possible, in the future, for PlayFab SDK to use for the WWW Post the timeout value from PlayFabSettings.RequestTimeout (or another setting)?

Thank you and Best Regards,

Alex

EZ ENTERTAINMENT

Authentication
10 |1200

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

6 Comments

·
brendan avatar image
brendan commented

I take it you're referencing this thread? http://answers.unity3d.com/questions/566671/any-way-around-www-timeout-on-android.html

In general, it should be relatively safe to have a shorter timeout for Login calls, as the majority of the time any of those requests take more than 5 seconds to return, you're looking at a failure case. However, that's not long enough for all calls in the service, technically. In specific, the ExecuteCloudScript call may take slightly more than 5 seconds to return, since the maximum runtime on a Cloud Script is itself 5 seconds. So I'd have to recommend setting your generalized timeout higher, and doing thorough testing to ensure that you've checked all your use cases.

10 |1200

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

ezentertainmentstudio avatar image
ezentertainmentstudio commented

Hello Brendan,

Thank you kindly for your reply.

Indeed, the question is related to the thread you mentioned, although our particular problem came strictly from how long it takes to authenticate the user to PlayFab, regardless of platform - because, in our case, the game initialization is halted waiting for the login to either succeed or fail.

We will go with a timeout of 10 seconds, then, just in case and perform some more testing.

Still, if possible, it may prove useful in the future to allow a finer control of various timeouts using PlayFabSettings class.

Best Regards,

Alex

EZ ENTERTAINMENT

10 |1200

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

brendan avatar image
brendan commented

Actually, if you use WebRequest instead, we do have a timeout defined in PlayFabSettings - would that be an option for you?

10 |1200

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

ezentertainmentstudio avatar image
ezentertainmentstudio commented

Hello Brendan,

Yes, that would certainly be a valid option. However, I have found no way to specify which option the Login methods should use (Post or WebRequest). Is it possible to select this?

Thank you,

Alex

EZ ENTERTAINMENT

10 |1200

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

brendan avatar image
brendan commented

For non-Windows Phone (WSA and WP8) platforms, you can set your WebRequestType to HttpWebRequest in your PlayFabSettings. That will cause the Unity SDK to use WebRequest, rather than WWW. But to be clear, the request uses the "post" method in either case.

10 |1200

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

ezentertainmentstudio avatar image
ezentertainmentstudio commented

Sorry, when I wrote "post" I meant "WWW Post". I think we will stick with our little hack, for now, as testing suggests that using WWW it is faster than HttpWebRequest.

Thank you very much for your support!

Best Regards,

Alex

10 |1200

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

Write a Comment

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

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.