question

omar avatar image
omar asked

Possible garbage on cloudscript

We have cloud script with some global variables declared. We fill those variables in different methods inside our logic. One of the methods append a string to a variable, but consecutive calls to execute cloud script show that variable having duplicates of the appending that only happens once per call. We already implemented it so the problem doesn't happen but I want to understand more about how cloud script works because I couldn't find a single clue in the documentation regarding this issue. The code was something like this:
myVar = "";
MyAppend = function (data)
{
  myVar += "myData";
} 
Then when I returned the value of myVar, sometimes I got:
{ "result" : "myData" } 
And some other times:
{ "result" : "myDatamyData" } 
Apparently at random. My guess is that the cloud script is saved somehow in between calls, like a reused instance, and if that is the case we need to know it for sure, so our implementations are made within those design restrictions. Thanks in advance.
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

·
Joshua Strunk avatar image
Joshua Strunk answered

tl;dr: Yes, your assumption is correct. Static values are maintained on an instance across runs because it will reuse a spun up Cloud Script engine as long as requests keep coming in for it to process.

I can no longer find a link to their 2016 technical white paper but you can find it on google by searching, playfab 2016 technical white paper.

Here are the bits about Cloud Script.

  • All CloudScript requests forwarded to a separate pool of autoscaling EC2 instances with extremely limited role permissions no direct data access
  • Scripts execute in the V8 JavaScript engine
  • Preauthenticated server API, log collector, and HTTP client exposed as script objects using ClearScript engine host
  • Process isolation between scripts from different titles

And here is a link to a relevant forum question JS static properties and Cloud Script

4 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.

brendan avatar image brendan commented ·

The whitepaper is on our docs page now, but here's a direct link: https://api.playfab.com/downloads/technical-white-paper.

Also, @omar: Whether or not the instance of the logic server is reused is not something you can rely upon. Your title may be using one logic server or it may be using several, and those may swap out from time to time. So if you use static data, any given call to a Cloud Script may have it from a previous call - which could have been made by another user - or it may not.

1 Like 1 ·
omar avatar image omar brendan commented ·

@Brendan that is exactly what I meant with "Our implementations are made within those design restrictions" and what we did with our logic, make sure that the state of the script starts fresh even if it's a reused instance.

Thanks again.

0 Likes 0 ·
brendan avatar image brendan omar commented ·

If your script assumes that any statically defined variables potentially contain garbage information, and so should not be re-used on a fresh call, then you should be fine.

0 Likes 0 ·
omar avatar image omar commented ·

Thank you very much.

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.