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

[5.x] Fix JobWatcher when processing deleted instance of SerializesModels #1539

Merged
merged 17 commits into from
Oct 29, 2024

Conversation

hapidjus
Copy link
Contributor

If there is a failure when unserializing the command, (for instance if the job deleted a model it received, of the database connection is set dynamically) the jobs will never proceed to processed. See #1479

In this PR unserialize is removed in favor of preg_replace to extract the batch_id

@taylorotwell taylorotwell marked this pull request as draft October 24, 2024 14:01
@crynobone
Copy link
Member

@hapidjus shouldn't we use the new approach only if unserialize() return an exception?

@hapidjus
Copy link
Contributor Author

hapidjus commented Oct 25, 2024

@hapidjus shouldn't we use the new approach only if unserialize() return an exception?

Makes sense.
This PR was mainly to confirm that using preg_match is a reasonable approach here.
The PR currently doesn’t handle encrypted data or include any tests.

However I'm not sure we can catch exceptions that happens "inside" the unserialize function. It's not necessarily unserialize() that throws.

@hapidjus
Copy link
Contributor Author

I've updated the PR now to try to unserialize first and only use preg_match as fallback.

@crynobone
Copy link
Member

@hapidjus Thanks, I'll review it and possibility add some tests to cover the new use case. Will mark it as ready when I'm done with it

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone marked this pull request as ready for review October 26, 2024 07:11
@crynobone crynobone changed the title Replace unserialize with preg_match in JobWatcher [5.x] Fix JobWatcher when processing deleted instance of SerializesModels Oct 26, 2024
@@ -266,7 +267,7 @@ protected function getBatchId(array $data)
$properties = ExtractProperties::from($command);

return $properties['batchId'] ?? null;
} catch (\Exception|\Error) {
Copy link
Contributor Author

@hapidjus hapidjus Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understrand that catch (\Exception|\Error) is a bit greedy. But there are other ways that the unserialize can go wrong. For instance when in a multi tenancy context and the database connection has not been set yet. See this issue for instance archtechx/tenancy#1263

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there a use case to include other exceptions we need to see the actual use case and replication steps so we can add tests to cover that usage. Having the scope too wide add a huge risk to this PR getting rejected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll see if I can make a minimal reproduction of it. Bur for now I'm happy to have this merged and make another PR later.

@taylorotwell taylorotwell merged commit 749369e into laravel:5.x Oct 29, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants