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

Add secondary scheduled date checks when claiming actions (DBStore) | #634 #668

Merged
merged 8 commits into from Mar 3, 2021

Conversation

barryhughes
Copy link
Member

@barryhughes barryhughes commented Feb 27, 2021

🎫 #634 → Double check action scheduled date in case they're processing too early

Closes #634

😖 The Problem

We can broadly divide pending scheduled actions into two categories:

  • Those that are due now.
  • Those that are not due until some future point in time.

When the Queue Runner claims a set of actions it does so with a query that is designed to ignore those actions that are not yet due, which makes sense (as a commenter in the linked issue noted, we want to make sure the scheduled date is not in the future before running it).

However, there's a body of reported evidence suggesting that—under unusual conditions, such as if MySQL finds it is out of disk space—the WHERE conditions we use to enforce this are seemingly not respected. To combat this, we need an extra set of checks that run at PHP-level.

🛠️ This Changeset

We were already specifying a $before_date when claiming actions (defaulting to 'now') ... with this change, we also test at PHP-level after fetching the individual actions to make sure that the $before_date condition was respected (we don't just rely on MySQL).

This way, besides adding extra safety for common cases, if some custom code wishes to stake a claim that explicitly includes future pending actions (by specifying a $before_date in the future) then that custom code should still function as previously.

📝 Some Notes

  • I have focused on the DBStore in this PR. Let's confirm we're happy with this approach/refine and adjust as needed, and I can follow-up with a corresponding change for the wpPostStore.
  • Try as I might, I could not actually replicate the problem so I've done my best to simulate it in the test suite by intercepting the claim staking query and modifying it so that it also claims future actions. My thinking is this replicates a situation where the DBStore builds a query that should ignore actions that are not yet due, but where MySQL returns them anyway).

@rrennick
Copy link
Collaborator

under unusual conditions, such as if MySQL finds it is out of disk space—the WHERE conditions we use to enforce this are seemingly not respected.

The specific situation where this was observed is that MySQL was out of temporary disk space (which is required when joining tables). When that occurred during a claim query, MySQL ignored the WHERE clause which requires a join and retrieved action IDs according to the order of the PRIMARY KEY and the LIMIT clause of the query.

*
* @var array
*/
private $before_dates_by_claim_id = array();
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 I'm using a private field to share this information rather than modify any of the method signatures (this is for backwards compatibility reasons...if we altered some of the methods to add a new optional param, and passed the information that way, then under PHP 8.0+ we'd face errors if third-party sub-classes didn't update in time).

Copy link
Contributor

@claudiosanches claudiosanches left a comment

Choose a reason for hiding this comment

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

@barryhughes Great work solving this issue, special kudos for the unit test introduced, nice way to try to reproduce it. I agree that's a hard one to reproduce.

@rrennick do you like to also review this change?

Copy link
Contributor

@claudiosanches claudiosanches left a comment

Choose a reason for hiding this comment

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

I left some notes about small tweaks that we could do in this PR.

classes/data-stores/ActionScheduler_DBStore.php Outdated Show resolved Hide resolved
classes/data-stores/ActionScheduler_DBStore.php Outdated Show resolved Hide resolved
barryhughes and others added 2 commits March 2, 2021 09:01
Co-authored-by: Claudio Sanches <contato@claudiosanches.com>
@barryhughes
Copy link
Member Author

Updated, thank you!

Copy link
Contributor

@claudiosanches claudiosanches left a comment

Choose a reason for hiding this comment

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

Looks great!

@rrennick
Copy link
Collaborator

rrennick commented Mar 2, 2021

Looks great for me too. Okay to merge once it clears Travis.

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.

Double check action scheduled date in case they're processing too early
3 participants