Skip to content

Prevent multiple execution of aborted jobs #528

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

luke-
Copy link
Contributor

@luke- luke- commented May 19, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues

We have the situation that apparently in some environments, jobs canceled by max_execution_time are not correctly removed from the queue. As a result, they are executed again and again. Even if no RetryableJobInterface is implemented or canRetry() always returns false.

Unfortunately, I can't reproduce it myself, but some users can in connection with CPanel environments. Perhaps the worker is there not running in CLI but in CGI mode.

In our project, we have now successfully solved the problem using the ExecEvent. But maybe it makes sense to add this fix (even if I am not completely happy with it) to the upstream queue project.

Related issue: humhub/calendar#547

Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

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

That sounds like a valid case. Would you please add a line for CHANGELOG? Thanks.

@luke-
Copy link
Contributor Author

luke- commented May 21, 2025

@samdark Thanks for the feedback. I still need to investigate why the tests are failing. After that, I'll adapt the CHANGELOG.

src/Queue.php Outdated
if ($job instanceof RetryableJobInterface && !$job->canRetry($attempt - 1, $error)) {
return true;
} else {
// Non RetryableJobs can have a maximum of one attempt
Copy link

Choose a reason for hiding this comment

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

This assumption is incorrect. RetryableJobInterface means that job can decide whether it should be retried. In other case it is controlled by attempts property at queue level - job can still have multiple retries even if it doesn't implement RetryableJobInterface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rob006 Thanks for pointing that out. I've adjusted the condition.
However, I still need to check the tests.

@luke-
Copy link
Contributor Author

luke- commented May 21, 2025

I was able to fix the tests. Unfortunately, PHP 5.4 and PHP 7 fail for other reasons. I don't have time to investigate this further at the moment.

I'm not entirely happy with my fix/PR, as these failed jobs are closed without any error message. Unfortunately, no specific error is available either. At least these jobs are not executed multiple times.

@@ -225,6 +225,16 @@ public function getWorkerPid()
protected function handleMessage($id, $message, $ttr, $attempt)
{
list($job, $error) = $this->unserializeMessage($message);

// Handle aborted jobs without thrown error
if ($attempt > 1) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that all this can be combined into one condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@s1lver Shall I summarize that? I'd be happy to. I personally prefer the breakdown for quick readability.

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.

4 participants