frankenphp
73d4974d - fix: coalesce opcache_reset() calls within the cooldown instead of dropping them

Commit
109 days ago
fix: coalesce opcache_reset() calls within the cooldown instead of dropping them @alexandre-daubois caught two real bugs in review: 1. A call landing inside the cooldown did nothing at all, yet frankenphp_opcache_reset() unconditionally reports success to PHP. If a burst ends on such a call, the reset it wanted never happens - and since the same hook fires on an internal opcache restart (OOM), a dropped one could leave the accelerator disabled indefinitely. 2. lastOpcacheResetAt was stamped before rebootAllThreads() ran, whose return value was discarded. rebootAllThreads() can no-op (already rebooting, or the pool isn't Ready), so a no-op call could still arm a fresh cooldown window and swallow the next, legitimate request. Fix: track whether a reboot is scheduled, in flight, or in its post-reboot cooldown hold, and coalesce any calls arriving during that whole span into the one pending/just-finished reboot instead of dropping them. Only stamp lastOpcacheResetAt after rebootAllThreads() actually returns true. Holding the cooldown through a full window after completion (not just until the reboot itself finishes) matters here: threads can yield well within a grace period, so without it, a call landing in the gap between "reboot done" and "cooldown elapsed" would open a second window instead of joining the first. That trailing hold introduced its own bug, caught by -race: the goroutine holding it can outlive Shutdown() by design (it's coalescing calls that might still arrive), but it read the package-level mainThread var again after waking up - which a later, unrelated test's Init() had by then reassigned to a different instance, racing on that instance's own fields. Fixed by capturing the *phpMainThread once and using only that local copy for the goroutine's lifetime, and by selecting on its done channel to give up immediately once its specific instance starts shutting down rather than waiting out an arbitrary delay first.
Author
Parents
Loading