Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aws SQS: VisibilityTimeout value is zero and type is string instead integer #2893

Closed
nepos87 opened this issue Mar 6, 2024 · 5 comments
Closed
Assignees
Labels
guidance Question that needs advice or information.

Comments

@nepos87
Copy link

nepos87 commented Mar 6, 2024

Describe the bug

Using Laravel 5.5 and processing a job with AWS Sqs, only if I have an error during processing, the queue returns the following error message:

ErrorException: The provided type for VisibilityTimeout value was string. The modeled type is integer. in C:\Users\Win\public_html\project\vendor\aws\aws-sdk-php\src\QueryCompatibleInputMiddleware.php:173

In particular, within the Laravel SqsJob.php file, in the following function, the variable $delay is equal to 0 (i.e. it arrives with a value of zero and does not take the default one in brackets) but with a string data type instead of an integer:

public function release($delay = 0)
     {
         echo gettype($delay); // string instead integer

         parent::release($delay);

         $this->sqs->changeMessageVisibility([
             'QueueUrl' => $this->queue,
             'ReceiptHandle' => $this->job['ReceiptHandle'],
             'VisibilityTimeout' => $delay,
         ]);
     }

But within the aws control panel the queue is set to the default value of 30 seconds in Visibility Timeout. Despite this, the $delay parameter in function arrives with a value of zero and in string format instead of integer.

Expected Behavior

The value of $delay must be 30 seconds and of type integer

Current Behavior

The value of $delay has a value of zero and of type string

Reproduction Steps

When a job fails

Possible Solution

public function release($delay = 0)
     {
         echo gettype($delay); // string
         $delay = (int) $delay;
         echo gettype($delay); // integer

         parent::release($delay);

         $this->sqs->changeMessageVisibility([
             'QueueUrl' => $this->queue,
             'ReceiptHandle' => $this->job['ReceiptHandle'],
             'VisibilityTimeout' => $delay,
         ]);
     }

Additional Information/Context

No response

SDK version used

aws-sdk-php: 3.300.11
aws-sdk-php-laravel: 3.8.1

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 7.4 - Laravel 5.5

@nepos87 nepos87 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 6, 2024
@nepos87
Copy link
Author

nepos87 commented Mar 7, 2024

I did several tests with different versions of aws-sdk-php and discovered that the bug appears from version 3.285.1. Before this version (for example in 3.285.0) the bug does not occur.
Can this problem be solved? Thank you

@stobrien89
Copy link
Member

stobrien89 commented Mar 7, 2024

Hi @nepos87,

Sorry to hear about the issues. Could you point me to the exact location of the SqsJob.php file?

Recently, SQS migrated their protocol from query to json. What we discovered in that process is that (by happenstance via a mistake in one of our tests) is that because the params were all built into/parsed out of a query string, SQS would accept string values for parameters modeled as ints. This however does not work with json protocol services where the values are extracted from the payload.

The middleware emitting the warning you're seeing actually casts any incorrectly typed values it finds— the intent was to avoid breaking customers who were unintentionally sending strings for params modeled as ints or any other permutation of incorrectly typed scalar values.

@stobrien89 stobrien89 added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 7, 2024
@stobrien89 stobrien89 self-assigned this Mar 7, 2024
@nepos87
Copy link
Author

nepos87 commented Mar 8, 2024

Hi @stobrien89,

Thanks for the explanation.
The SqsJob.php file is located here: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Queue/Jobs/SqsJob.php

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 9, 2024
@stobrien89
Copy link
Member

Hi @nepos87,

Thanks for the clarification. The fix would need to come from the laravel side, since it appears they're sending an incorrect type. Alternatively, you could pin your SDK version to <=3.285.0 which is the last release that SQS used query protocol, but this is not recommended.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants