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

feat(loader): lock load class on file loader to avoid race condition #174

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

joelwurtz
Copy link
Member

@joelwurtz joelwurtz commented Jul 16, 2024

There can be race condition when multiple php process would generate the class at the same time, so we add a lock here to avoid this problem

Better diff with ?w=1

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks

@@ -40,25 +42,33 @@ public function loadClass(MapperMetadata $mapperMetadata): void
$className = $mapperMetadata->className;
$classPath = $this->directory . \DIRECTORY_SEPARATOR . $className . '.php';

if ($this->reloadStrategy === FileReloadStrategy::NEVER && file_exists($classPath)) {
require $classPath;
// We lock the file here, because another process could be writing the file at the same time
Copy link
Member

@Korbeil Korbeil Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we wait until the other process is done (waiting on lock release) until returning this method ?
So we are sure the file is generated.

@Korbeil Korbeil merged commit deb3f27 into main Aug 30, 2024
10 checks passed
@Korbeil Korbeil deleted the feat/lock-load-class branch August 30, 2024 13:20
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