Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache race condition due to missing repopulation of lock files cache #8714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -361,7 +361,7 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
}

if ($this->file_reference_provider->cache) {
$this->file_reference_provider->cache->hasConfigChanged();
$this->file_reference_provider->cache->setConfigHashCache();
}

$this->project_cache_provider->updateComposerLockHash();
Expand All @@ -377,8 +377,10 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
Config::removeCacheDirectory($cache_directory);
}

$this->file_reference_provider->cache->setConfigHashCache();

if ($this->project_cache_provider) {
$this->project_cache_provider->hasLockfileChanged();
$this->project_cache_provider->updateComposerLockHash();
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/Psalm/Internal/Provider/FileReferenceCacheProvider.php
Expand Up @@ -66,9 +66,7 @@ public function __construct(Config $config)
public function hasConfigChanged(): bool
{
$new_hash = $this->config->computeHash();
$has_changed = $new_hash !== $this->getConfigHashCache();
$this->setConfigHashCache($new_hash);
return $has_changed;
return $new_hash !== $this->getConfigHashCache();
}

/**
Expand Down Expand Up @@ -998,14 +996,18 @@ public function getConfigHashCache()
return false;
}

public function setConfigHashCache(string $hash): void
public function setConfigHashCache(string $hash = ''): void
{
$cache_directory = Config::getInstance()->getCacheDirectory();

if (!$cache_directory) {
return;
}

if ($hash === '') {
$hash = $this->config->computeHash();
}

if (!is_dir($cache_directory)) {
try {
if (mkdir($cache_directory, 0777, true) === false) {
Expand Down