Skip to content

Commit

Permalink
Merge pull request #8714 from kkmuffme/dont-rewrite-config-hash-to-ca…
Browse files Browse the repository at this point in the history
…che-when-unchanged

Fix cache race condition due to missing repopulation of lock files cache
  • Loading branch information
orklah committed Nov 18, 2022
2 parents 4a83f88 + ff49dfc commit 4e17585
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -369,7 +369,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 @@ -385,8 +385,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

0 comments on commit 4e17585

Please sign in to comment.