FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Changed ExposedRoutesExtractor to handle mkdir warnings #434

Closed mnocon closed 2 years ago

mnocon commented 2 years ago

Hi!

I believe there's an issue in this bundle that can occur when the Controller:indexAction is invoked for the first time.

We have a test suite with browser tests that runs in parallel and from time to time we see failures like this in the logs:

request.CRITICAL: Uncaught PHP Exception ErrorException: 
"Warning: mkdir(): File exists" at /var/www/vendor/friendsofsymfony/jsrouting-bundle/Extractor/ExposedRoutesExtractor.php line 179 
{"exception":"[object] (ErrorException(code: 0): 
Warning: mkdir(): File exists at /var/www/vendor/friendsofsymfony/jsrouting-bundle/Extractor/ExposedRoutesExtractor.php:179)"} []

There's a race condition in the code which can lead to this error - my suggestion is to make it a bit more bullet-proof.

The other mkdir usage in this package is already "hardened": https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/089c7380eaaacf776f99c6fbf51f787d395b2013/Command/DumpCommand.php#L126-L131

and I've based my solution on that.

tobias-93 commented 2 years ago

Thanks @mnocon