Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 10 comments

2 participants

@doctrinebot

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 fileputcontents is not atomic.

@doctrinebot

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

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

Comment created by @beberlei:

we should just change fileputContents into:

file*put_contents($fileName, $file, LOCK*EX);
@doctrinebot

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

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

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

Comment created by jakajancar:

I'm not setting it to false!

When doing concurrent requests with autogeneration of proxies enabled

@doctrinebot

Comment created by @beberlei:

ah ok, eval is just a workaround.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-BETA3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.