Repository navigation
Conversation
PHP 8.5.12's OPcache can flag a newly interned shared class name as having a CE-cache slot before it stores the slot's map_ptr offset (php-src GH-24577; on amd64 GCC emits the flag store before the offset store in zend_accel_pending_ce_cache_commit). A forked Swoole worker that links a class in that window reads the string's refcount, 2, as the offset and writes that class pointer across map_ptr slots 0 and 1. ext/date registers first at startup, so slot 1 is always DateTime's: its cached class entry loses its low byte and every DateTime type check in that worker fails with "must be of type DateTime, DateTime given" (Sentry CLOUD-3R2D) until the worker exits. php-src 47d5c0c fixes it and first ships in 8.5.13RC1, so the test requires PHP_VERSION_ID >= 80513 (RC1 reports 80513; version_compare would reject "8.5.13RC1"). The image still runs 8.5.12 at this commit, so the structure test fails until the following fix commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PHP 8.5.12's OPcache can flag a newly interned shared class name as having a CE-cache slot before it stores the slot's map_ptr offset (php-src GH-24577; on amd64 GCC emits the flag store before the offset store in zend_accel_pending_ce_cache_commit). A forked Swoole worker that links a class in that window reads the string's refcount, 2, as the offset and writes that class pointer across map_ptr slots 0 and 1. ext/date registers first at startup, so slot 1 is always DateTime's: its cached class entry loses its low byte and every DateTime type check in that worker fails with "must be of type DateTime, DateTime given" (Sentry CLOUD-3R2D) until the worker exits. php-src 47d5c0c fixes it and first ships in 8.5.13RC1; php:8.5-alpine still serves 8.5.12. The pinned digest is php:8.5.13RC1-alpine's multi-arch index, kept under the php:8.5-alpine name because the updater's Dockerfile::pins, which StructureTest also runs, rejects any other tag. Meanwhile the image's base_image label reads php:8.5-alpine@<RC digest>. Costs: until php:8.5-alpine serves 8.5.13, the weekly updater proposes 8.5.12's digest and its pull request fails the new structure test. Because the updater bundles every pin into one pull request, all other dependency updates are blocked meanwhile. Once php:8.5-alpine serves 8.5.13, the updater re-pins it with no manual step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
|
PHP 8.5.13 went GA today, so #150 pinned the GA digest and shipped as 2.4.2. This RC pin is no longer needed. |
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.
Symptom
Sentry CLOUD-3R2D (4827 events):
TypeError: Utopia\Database\DateTime::addSeconds(): Argument #1 ($date) must be of type DateTime, DateTime given. The cloud call site passesnew \DateTime().The same pod and time windows also produced these sibling issues. Every one is a
DateTimecheck, covering arguments, nullable arguments and return values across three repos:DateTime::formatAdapter\Pool::getMinDateTime(): Return value must be of type DateTime, DateTime returnedValidator\Query\Filter::__constructAdapter\Limits::__constructEvent\Message\Usage::__construct(?DateTime)Root cause
PHP 8.5.12's OPcache has a race when it publishes the class-name cache (php-src GH-24577, fixed by 47d5c0c).
When a script is persisted,
zend_accel_pending_ce_cache_commit()does two things to each newly interned class name in shared memory:IS_STR_CLASS_NAME_MAP_PTRflag;map_ptroffset in the refcount field.On amd64, GCC emits the flag store first (
orl $0x20,0x4(%rdx)at0x47ff84, thenmovl %esi,(%rdx)at0x47ff88).A forked Swoole worker can see the flag before the offset is stored. It then takes the string's placeholder refcount,
2, as the offset.At offset 2, the 8 bytes span map_ptr slot 0 (bytes 1 to 7) and the low byte of slot 1.
ext/dateregisters first at startup, so slot 1 always holdsDateTime's cached class entry.If the worker links a class in that window, it writes that class's pointer across those bytes. This zeroes the low byte of
DateTime's cachedzend_class_entry *.From then on, every
DateTimetype check in that worker fails: the object's class does not match the corrupted pointer, but both print asDateTime. This lasts until the worker exits.If the worker reads in the window instead, it gets a non-canonical pointer and segfaults.
This explains why only
DateTimeis affected, and why a band-aid on one method cannot fix it.Confirmed
src/Database/DateTime.phpdeclaresuse DateTime as PhpDateTime, which resolves to the global\DateTime.new \DateTime().Utopia\Database\DateTime, so that explanation does not fit.78911b06ff(opcache.jit=disable) is an ancestor of 1.50.99, 1.51.44 and 1.51.73.utopiaextension is not the cause. It was added to cloud on 2026-11-11, after the last event.DateTimeis never racily flagged itself.accel_copy_permanent_stringscopies it into shared memory, flag included, before the fork.appwrite/baseand inphp:8.5.12-cli-alpine.DateTime's cached pointer0x…b60into0x…b00;\DateTime-typed call throwmust be of type DateTime, DateTime given;DateTimeZone,Closure,Throwableand user-class checks passing.php-8.5.13RC1and not inphp-8.5.12. Production runs on amd64 nodes, checked with read-onlykubectl get nodes -L kubernetes.io/arch.Inferred
swoole_cpu_num() * 6workers sharing one cold shared-memory segment. The reproduction forces this case with a privately compiled class; it is not observed in production.Fix
Move the PHP base to 8.5.13RC1, which contains 47d5c0c. Add a structure test that fails on any image older than 8.5.13.
php:8.5-alpine. The pin isphp:8.5.13RC1-alpine's multi-arch index digest, placed on thephp:8.5-alpine@sha256:…line. The dependency updater'sDockerfile::pins, whichStructureTestalso runs, rejects any other tag.php:8.5-alpineserves 8.5.13, the weekly updater re-pins the digest with no manual step.\DateTimeInterface. That only stops the corruptedDateTimecache slot being consulted in those two methods. The otherDateTimechecks in the sibling issues above stay broken, and the worker'sinstanceof \DateTimeandnew \DateTimeremain corrupted.opcache.interned_strings_buffer=0in cloud would also remove the race: 0 hits in the matrix below. It costs per-worker memory, so it is only an interim option if GA is far off.Proof
1. Regression test.
tests.yamlgainsPHP is 8.5.13 or newer (OPcache fix for php-src GH-24577), which checksPHP_VERSION_ID >= 80513(RC1 reports 80513). Commit order is test first, then fix. The images were built with--target finaland run withcontainer-structure-test.Other checks on HEAD:
tests-swoole.php: OK.tests-xdebug.yaml: 1 of 1 pass.php -mis unchanged from the 8.5.12 image.2. Amplified race reproduction. These are PHP builds from source.
8.5.12ampbuild keeps 8.5.12's flag-then-offset order and adds an env-gatedusleepbetween the two stores. That call widens the window without reordering anything.8.5.13RC1ampbuild puts the same sleep after the release fence.\DateTime,?\DateTimeandDateTime-return functions plus a user-class-typed function.must be of type DateTime, DateTime giveninterned_strings_buffer=32(cloud)interned_strings_buffer=0interned_strings_buffer=32interned_strings_buffer=0PhpDateTimeform. The user-class-typed checks never failed.DateTimecheck, including a probe made after the window had closed.Collisions
CONFLICTING) re-pins the same line to another 8.5.12 digest. It would now fail the new test. It is superseded by this PR or by the next weekly run.php:8.5-alpineserves 8.5.13, the weekly updater's bundled pull request will fail the new test. Every other dependency update in that bundle is blocked with it.CHANGES.mdentry here moves to the next patch version.base_imagelabel. The image's label readsphp:8.5-alpine@<RC digest>while the RC is pinned.Follow-up
ARG BASE_IMAGEto the release that contains this change.Supersedes
🤖 Generated with Claude Code