question

robert avatar image
robert asked

ExecuteFunction, Azure return data gzip not working

When we return gzipped data from an Azure function back to cloudscript, it appears playfab does not unzip the data when writing it to the functions result.

This is an example data we receive on the client:

{"code":200,"status":"OK","data":{"ExecutionTimeMilliseconds":343,"FunctionName":"PlayerLogin","FunctionResult":"�\b\0\0\0\0\0uS]o�0�+��Cd��<�T=�:�q&Y8��A��+E��];�T��%�gf���ə���X�\n��J���Ԃ�HjM\rY�y�R\aX�F$%�r֡��ي�T��+B&�/�u���R�Ծ�[U���,3�7$��8}��>��Y�!���ײP��,�Ӱ�y`*���ǽn\fO*�Y�C�q5�K����c\b�̗7?o�g�������a7�����,\n�۞�%�B�]i�ܔ\n%M��\\����Dn�9�\f����&�p��V����,� �[��T�����i���{�E�q��\n\f�8+��T���\bC�h�\v\\\0��#pUa��`\"/��0�Eq�v{\b����w�� �+�����ʮ�9����������8eI(D��\0sP�[���Pi2�l��q:~o��1�(�q��&�F��D�EHc�e�[��`N���s�6�ĹY4��uqÒ���n�WZRe�2�\a ����\v1]U��!��yi�O�@��\\�G�\aq�o�AC��z&\n�\0\0","FunctionResultTooLarge":false}}


Flow:
Client calls ExecuteFunction (accept-encoding:gzip)
Playfab calls Azure (accept-encoding:gzip, content-encoding:"")
We return gzipped data (content-encoding:gzip)
Playfab returns to the client

Here, FunctionResult is still the gzipped content

We would assume playfab decompressed the content it received from azure, builds the final json and gzippes it again when returning to the client

The major problem here is that suddenly the returned data size can increase dramatically when switching from cloudscript to azure, resulting in multiple failed functions because of a too big data size returned from azure to playfab

P.s.: The same issue happens when using ExecuteFunction.cs for local azure debugging. It is clearly visible in the code that the returned data from Azure is never unzipped but just written into the FunctionResults property and the entire JSON is than compresses again if accept-encoding:gzip is set

P.p.s: It also looks like that playfab never compresses the data it returns to the client with ExecuteFunction, regardless if CompressApiData is true or accept-encoding is set to gzip

1 comment
10 |1200

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

Citrus Yan avatar image Citrus Yan commented ·

In Azure Function, GZip is configured ON by default. Do you mean that you GZipped the result again in the code?

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Azure do compresses the result to gzip by default, however, when it reached to PlayFab it will get unzipped. By default, PlayFab support the response size of 65536 bytes from Azure, therefore if the unzipped result size is too large (larger than 65536 bytes), the error CloudScriptAzureFunctionsReturnSizeExceeded will occur.

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

robert avatar image robert commented ·

I fully understand that there must be a return data size limit, but is it by design that its not possible to return just 6KB of compressed data? Is there any special reason triggering the size check on the uncompressed data and not on the compressed?

With this limit in place there is no way around for us to use Azure directly from the client for most functions. We cannot used cloudscript anymore because of the VM limitations (having to run in vertical) and cannot use ExecuteFunction because of the return data size limitation, even for functions with egress of < 30KB mostly (as said, we would fully understand a 64KB limit as return data size, but for the compressed, actual transmitted data)

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan robert commented ·

PlayFab handles the uncompressed data, this is by design. Do you have access to support tickets? If so, please create one so that you can discuss with our engineers over the possibility of raising the return data size limit.

0 Likes 0 ·
robert avatar image
robert answered

yes, we gzipped the return data manually as I’m pretty sure the result isnt gzipped by default. for example, returning a 150kb string results it data too large (if we zip manually to 6kb, playfab accepts the returned data) ?

Also, as written in the initial post, the returned data from playfab to the client for an ExecuteFunction is also never compressed

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.

Citrus Yan avatar image Citrus Yan commented ·

Based on the current situation, most likely the return data got gzipped twice, you can try unzip the function result returned by PlayFab again and see if it's the correct data returned by Azure Function.

0 Likes 0 ·
robert avatar image robert Citrus Yan commented ·

This is what we tried already, but for some reason the compressed FunctionResult is always corrupt, but just in the second byte (the magic gzip bytes 31, 139 always return as 31, 239), the remaining data is correct

But, besides the corruption why would we receive the return data too large in this case? We don't get this issue if we compress ourself. If Azure compresses by default, we shouldn't get this error for a 150KB return array which gzip compresses to 6KB, correct?

Also, as written in the initial post, the returned data from playfab to the client for an ExecuteFunction is also never compressed, shouldn't the return data by compressed if CompressApiData is enabled?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan robert commented ·

I see, referring to this API referrence:

https://docs.microsoft.com/en-us/rest/api/playfab/cloudscript/server-side-cloud-script/executefunction?view=playfab-rest#executefunctionresult

"FunctionResultTooLarge" is a flag indicating if the FunctionResult was too large and was subsequently dropped from the event. Therefore, If the overall size of the "function_executed" event is too big due to the function result and other contextual information consuming too much space, "FunctionResultTooLarge" will be true. You can try setting "GeneratePlayStreamEvent" as false to see whether this issue still occurs.

0 Likes 0 ·
Show more comments

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.