DDC-716: Proxy autogeneration fails with concurrent requests #884

Closed
opened 2026-01-22 12:53:48 +01:00 by admin · 10 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 22, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jakajancar:

When doing concurrent requests with autogeneration of proxies enabled, the proxy file does not exist when ProxyFactory tries to use it:

Doctrine/ORM/Proxy/ProxyFactory.php(92): spl*autoload*call('MyClassProxy'))

I think this is because file_put_contents is not atomic.

Originally created by @doctrinebot on GitHub (Jul 22, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jakajancar: When doing concurrent requests with autogeneration of proxies enabled, the proxy file does not exist when ProxyFactory tries to use it: ``` Doctrine/ORM/Proxy/ProxyFactory.php(92): spl*autoload*call('MyClassProxy')) ``` I think this is because file_put_contents is not atomic.
admin added the Bug label 2026-01-22 12:53:48 +01:00
admin closed this issue 2026-01-22 12:53:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 22, 2010):

Comment created by jakajancar:

The following fixes it on Linux, but I think will not work in Windows (iirc, rename() on Windows won't work if the dest file already exists, much less atomically):


--- Proxy/ProxyFactory.php  (revision 2)
<ins></ins><ins> Proxy/ProxyFactory.php (working copy)
@@ -144,7 </ins>144,9 @@

         $file = str_replace($placeholders, $replacements, $file);

-        file*put*contents($fileName, $file);
<ins>        $tmpFileName = $fileName.'-'.uniqid('', true);;
</ins>        file*put*contents($tmpFileName, $file);
+        rename($tmpFileName, $fileName);
     }

     /****
@doctrinebot commented on GitHub (Jul 22, 2010): Comment created by jakajancar: The following fixes it on Linux, but I think will not work in Windows (iirc, rename() on Windows won't work if the dest file already exists, much less atomically): ``` --- Proxy/ProxyFactory.php (revision 2) <ins></ins><ins> Proxy/ProxyFactory.php (working copy) @@ -144,7 </ins>144,9 @@ $file = str_replace($placeholders, $replacements, $file); - file*put*contents($fileName, $file); <ins> $tmpFileName = $fileName.'-'.uniqid('', true);; </ins> file*put*contents($tmpFileName, $file); + rename($tmpFileName, $fileName); } /**** ```
Author
Owner

@doctrinebot commented on GitHub (Jul 22, 2010):

Comment created by jakajancar:

I don't even know why this is needed. Can't the file just be returned as string and eval()'d, instead of being written to a file and then require()'d?

@doctrinebot commented on GitHub (Jul 22, 2010): Comment created by jakajancar: I don't even know why this is needed. Can't the file just be returned as string and eval()'d, instead of being written to a file and then require()'d?
Author
Owner

@doctrinebot commented on GitHub (Jul 22, 2010):

Comment created by @beberlei:

we should just change file_put_Contents into:

file*put_contents($fileName, $file, LOCK*EX);
@doctrinebot commented on GitHub (Jul 22, 2010): Comment created by @beberlei: we should just change file_put_Contents into: ``` file*put_contents($fileName, $file, LOCK*EX); ```
Author
Owner

@doctrinebot commented on GitHub (Jul 22, 2010):

Comment created by @beberlei:

Setting the LOCK_EX constant now, this should solve the issue.

However in high concurrency scenarios the "autoGenerateProxyClasses" flag should always be FALSE and the proxies be generated during build-time.

@doctrinebot commented on GitHub (Jul 22, 2010): Comment created by @beberlei: Setting the LOCK_EX constant now, this should solve the issue. However in high concurrency scenarios the "autoGenerateProxyClasses" flag should always be FALSE and the proxies be generated during build-time.
Author
Owner

@doctrinebot commented on GitHub (Jul 22, 2010):

Comment created by jakajancar:

LOCK_EX doesn't fix it for me. Apparently it's still possible that the file doesn't exist:

E_WARNING (2): include(MyProxies/MyClassProxy.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Please note that my above uniqid+rename suggestion only works if more_entropy is true, if you decide to add it.

However, I'd much prefer having an option of just not using these files at all. I've created an Improvement ticket DDC-717 for this.

@doctrinebot commented on GitHub (Jul 22, 2010): Comment created by jakajancar: LOCK_EX doesn't fix it for me. Apparently it's still possible that the file doesn't exist: ``` E_WARNING (2): include(MyProxies/MyClassProxy.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory ``` Please note that my above uniqid+rename suggestion only works if more_entropy is true, if you decide to add it. However, I'd much prefer having an option of just not using these files at all. I've created an Improvement ticket [DDC-717](http://www.doctrine-project.org/jira/browse/DDC-717) for this.
Author
Owner

@doctrinebot commented on GitHub (Jul 23, 2010):

Comment created by @beberlei:

i now underestand what you are doing wrong.

if you set autogenerate = false you have to call doctrine orm:generate-proxies

@doctrinebot commented on GitHub (Jul 23, 2010): Comment created by @beberlei: i now underestand what you are doing wrong. if you set autogenerate = false you have to call doctrine orm:generate-proxies
Author
Owner

@doctrinebot commented on GitHub (Jul 23, 2010):

Comment created by jakajancar:

I'm not setting it to false!

When doing concurrent requests with autogeneration of proxies enabled

@doctrinebot commented on GitHub (Jul 23, 2010): Comment created by jakajancar: I'm not setting it to false! > When doing concurrent requests with autogeneration of proxies **enabled**
Author
Owner

@doctrinebot commented on GitHub (Jul 23, 2010):

Comment created by @beberlei:

ah ok, eval is just a workaround.

@doctrinebot commented on GitHub (Jul 23, 2010): Comment created by @beberlei: ah ok, eval is just a workaround.
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2010):

Comment created by @beberlei:

Closed again, See DDC-717 for a timetable of a fix using auto-generate = true in production.

@doctrinebot commented on GitHub (Jul 24, 2010): Comment created by @beberlei: Closed again, See [DDC-717](http://www.doctrine-project.org/jira/browse/DDC-717) for a timetable of a fix using auto-generate = true in production.
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jul 24, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#884