fix(events): prevent callbacks after failed transitions - #523
Open
sjinks wants to merge 2 commits into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens event execution by ensuring an event’s state transition (complete/reschedule) succeeds before running its callback, and by cleaning up acquired locks when that transition fails. It also adds unit coverage for one-time, recurring, and internal-event transition failure paths.
Changes:
- Add a
transition_event()hook point and early-return behavior to prevent callbacks after failed transitions. - Centralize lock cleanup via
release_event_locks()and invoke it on both transition failure and normal completion paths. - Add unit tests plus a fixture
Eventssubclass to simulate transition failures.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| includes/class-events.php | Moves complete/reschedule into a transition step and ensures locks are released when that step fails. |
| tests/unit-tests/test-events.php | Adds tests asserting callbacks don’t run and locks are handled correctly when transitions fail. |
| tests/unit-tests/fixtures/class-transition-failure-events.php | Introduces a test-only Events subclass that forces transition failures for deterministic testing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @@ -256,10 +256,11 @@ public function run_event( $timestamp, $action, $instance, $force = false ) { | |||
| } | |||
|
|
|||
| // Core reschedules/conpletes an event before running it, so we respect that. | |||
Comment on lines
+129
to
+136
| Lock::prime_lock( Events::LOCK ); | ||
|
|
||
| $result = $events->run_event( $event->get_timestamp(), md5( $event->get_action() ), $event->get_instance() ); | ||
|
|
||
| $this->assertSame( $error, $result ); | ||
| $this->assertSame( 0, $called ); | ||
| $this->assertSame( $event->is_internal() ? 1 : 0, Lock::get_lock_value( Events::LOCK ) ); | ||
| $this->assertSame( 0, Lock::get_lock_value( $events->get_lock_key_for_event_action( $event ) ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
php -l includes/class-events.phpphp -l __tests__/unit-tests/test-events.phpphp -l __tests__/unit-tests/fixtures/class-transition-failure-events.php./vendor/bin/phpcs --standard=phpcs.xml includes/class-events.php __tests__/unit-tests/test-events.php __tests__/unit-tests/fixtures/class-transition-failure-events.phpgit diff --check./vendor/bin/phpunit __tests__/unit-tests/test-events.php(blocked locally: WordPress test bootstrap at/tmp/wordpress-tests-liband its MariaDB database are unavailable)Fixes PLTFRM-2760.