Skip to content

Do not delete a container that another process has not journaled yet - #6797

Merged
staabm merged 1 commit into
phpstan:2.3.xfrom
SanderMuller:keep-unjournaled-fresh-containers
Oct 24, 2026
Merged

staabm merged 1 commit into
phpstan:2.3.xfrom
SanderMuller:keep-unjournaled-fresh-containers

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

The "Integration tests" job fails now and then with Nette\IOException: Unable to include '.../phpstan/cache/nette.configurator/Container_*.php'. In the Tests runs since 2026-10-06, this happened 8 times: 7 times on Windows in CommandHelperTest and AnalyseCommandTest, and once on Ubuntu. These tests run in parallel and share the default tmpDir, sys_get_temp_dir() . '/phpstan'.

Configurator::journal() records the container a process loads, and then deletes every container file that is not in the journal. A process writes a new container before it journals it. A concurrent process can delete that file in this gap, so the first process cannot include it. Users who run several PHPStan processes with different configurations and the same tmpDir hit the same error.

A container file that is not in the journal is now deleted only when it is more than a week old. A file that another process has just written is new, so it stays. The journal still removes containers that nobody used in the last week.

ConfiguratorJournalTest sets up a journal and container files of different ages, and checks which files journal() keeps. Without the fix, it fails on the new file that is not journaled yet.

To reproduce the race, I started six clear-result-cache processes at once, 20 times. Each process had its own configuration and all of them shared one tmpDir. On 2.3.x, three such runs had 8, 5 and 6 failed starts out of 120, all with Unable to include. With this change, two runs had no failed starts.

BaselineNeonErrorFormatterIntegrationTest failed 4 more times in the same period, with Could not clear result cache. or a JsonException. It uses the same tmpDir, so these failures may have the same cause. I could not confirm this.

🤖 Generated with Claude Code

PHPStan processes that share a tmpDir journal the containers they load,
and each one deletes the container files that are not in the journal.
A process writes a new container before it journals it, so a concurrent
process could delete the file before it was included. The process then
failed with "Unable to include ... Container_*.php". A file that is not
in the journal is now deleted only when it is more than a week old.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@staabm
staabm merged commit 43a651b into phpstan:2.3.x Oct 24, 2026
992 of 994 checks passed
@staabm

staabm commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Thank you!

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.

3 participants