Skip to content

fix: throttle opcache_reset()-triggered thread pool reboots - #2570

Open
dunglas wants to merge 1 commit into
mainfrom
fix-opcache-reset-reboot-storm
Open

fix: throttle opcache_reset()-triggered thread pool reboots#2570
dunglas wants to merge 1 commit into
mainfrom
fix-opcache-reset-reboot-storm

Conversation

@dunglas

@dunglas dunglas commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

go_schedule_opcache_reset() spawned a full PHP thread pool reboot on every single opcache_reset() call, with no rate limiting. A reboot pauses request handling across the whole pool (drains every thread, force-kills stragglers after a grace period, recreates the main thread).

Some applications call opcache_reset() on nearly every request — the reporter of #2553 found several WordPress plugins doing exactly this across 19 sites on one host. Each call triggers its own reboot, and the reboots compound into sustained, severe slowdowns (write error, stream closed, client disconnected in the logs) rather than a single blip.

Fix

Coalesce opcache_reset()-triggered reboots into at most one per 5s cooldown window. The first call in a burst still reboots immediately; calls arriving within the cooldown are skipped rather than each pausing the pool again. This only throttles the automatic opcache_reset() hook — RestartWorkers() (used by the watcher/hot-reload and any explicit caller) is untouched and always takes effect immediately.

Tests

  • TestOpcacheResetIsThrottled: 10 sequential opcache_reset() calls 50ms apart (well within the cooldown, but each landing after the previous reboot would have already finished) — fails with 10 reboots on the unpatched code, passes with 1 reboot with the fix.
  • Existing TestOpcacheReset stress test (500 concurrent requests spamming opcache_reset() under load) still passes.

Fixes #2553.

opcache_reset() was rebooting the whole PHP thread pool on every single
call, unthrottled. Some applications (e.g. WordPress plugins) call
opcache_reset() on nearly every request; each reboot pauses request
handling for the whole pool, which compounds into sustained, severe
slowdowns and dropped connections under real traffic.

Coalesce calls into at most one reboot per 5s cooldown instead.

Fixes #2553.
@henderkes

Copy link
Copy Markdown
Contributor

I don't think this would help as at least one of the cases I was able to reproduce this with was a client stall during go_post_read

@AlliBalliBaba

Copy link
Copy Markdown
Contributor

Also not sure this would help, #2553 says rebooting periodically fixes the issue and opcache_reset basically does the same thing as a reboot currently

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.

Request response times are getting incredibly slow

3 participants