Repository navigation
fix(preemption): chain the interrupt handler before suspending; run CI on PHP 8.6 - #41
Merged
Merged
Conversation
Current PHP builds (8.4.28+, 8.5.13+ and 8.6.0) check EG(vm_interrupt) when an internal call returns. The flag Preemptor::onTick() raises is therefore taken while the tick handler is still running, inside ext-pcntl's signal dispatch, where the engine blocks every fiber switch. The callback consumed the request there, Fiber::suspend() threw a FiberError it swallows, and no coroutine was ever preempted: seven preemption tests failed on all three minors with current interpreter builds. The callback now chains proceed() first and decides afterwards, outside the dispatch frame, and shouldPreempt() declines while a tick is being dispatched, leaving the request pending for the outer invocation. Also adds PHP 8.6 to every CI job (z-engine ~8.6.0@dev, resolving 8.6.x-dev until it is tagged), and drops a null-coalesce on a value PHPStan 2.3 proves non-null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FxhC1D34vSRsQVcgd3HwS6
Owner
Author
|
The PHP 8.6 legs are red at Generated by Claude Code |
z-engine tagged 8.6.0, so the PHP 8.6 line no longer needs its 8.6.x-dev branch: the constraint becomes ~8.4.2 || ~8.5.0 || ~8.6.0, every minor resolves a stable tag, and the docs drop the root-level workaround a consumer on PHP 8.6 needed until now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FxhC1D34vSRsQVcgd3HwS6
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.
The bug
With current PHP builds, preemption stopped working on all three minors. Locally, seven preemption tests fail on PHP 8.5.13 and on 8.6.0, for example
testACallFreeLoopDoesNotStarveAnotherCoroutineandtestAWorkerInAPreemptivePoolIsActuallyPreempted. CI was last green in August, on older patch builds.Cause: php-src added
ZEND_VM_FCALL_INTERRUPT_CHECKsites after internal calls return. There are 3 such sites in 8.4.0 and 8.5.0, and 7 in 8.4.28, 8.5.13 and 8.6.0. Here is what happens now:SIGALRMarrives and our callback runs first. No request is pending yet, so it does nothing and callsproceed(), which enters ext-pcntl's dispatch.Preemptor::onTick()setsrequestedand callsrequestInterrupt().zend_fiber_switch_block().shouldPreempt()consumes the request,Fiber::suspend()throwsFiberError: Cannot switch fibers in current execution context, and the callback swallows it.The request is lost on every tick.
preemptions()still counts up, but no coroutine is ever preempted. This is not a JIT issue: it reproduces with opcache and the JIT fully disabled.The fix
InterruptBridge::onInterrupt()now callsproceed()first and decides on preemption afterwards. By then pcntl's dispatch has returned, so the suspend is legal, and the tick is taken on the same slice instead of one slice late.Preemptorsets adispatchingTickflag aroundonTick(), andshouldPreempt()declines while it is set. The nested callback therefore leaves the request pending for the outer one.Also in this PR
~8.4.2 || ~8.5.0 || ~8.6.0, all stable tags (z-engine 8.6.0 is released).minimum-stability: dev/prefer-stablestay, becausephp-shared-data-extensionis still consumed fromdev-main.ItimerClock::bindLibc(): dropped?->/??on$failure. PHPStan 2.3 proves it is non-null after the loop and reported both as errors.Verified
tools/soak-preemption.php --seconds=20on 8.6: PASS (1100 coroutines, none left in the callback, memory flat)composer phpstan: clean;php-cs-fixer --dry-run: cleanMerge order: the 8.6 legs resolve
php-shared-data-extensionasdev-main, so merge lisachenko/php-shared-data-extension#34 first.🤖 Generated with Claude Code
https://claude.ai/code/session_01FxhC1D34vSRsQVcgd3HwS6