Skip to content

Commit 4188236

Browse files
committed
bug #25671 Remove randomness from dumped containers (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- Remove randomness from dumped containers | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - With this PR, the generated container is immutable by cache clearing: it doesn't contain any random string anymore (well, third party bundles can add random things back, but at least core doesn't). Since the class+file name of the container is based on a hash of its content, it means that they are now stable also. This should help fix some edge cases/race conditions during cache clears/rebuilds. (fabbot failure is false positive) Commits ------- 14dd5d1dbd Remove randomness from dumped containers
2 parents 3df4e11 + af0316d commit 4188236

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
3737
use Symfony\Component\DependencyInjection\Exception\LogicException;
3838
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
39+
use Symfony\Component\DependencyInjection\Parameter;
3940
use Symfony\Component\DependencyInjection\Reference;
4041
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
4142
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
@@ -1626,7 +1627,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
16261627

16271628
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
16281629
{
1629-
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
1630+
$version = new Parameter('container.build_id');
16301631
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
16311632
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
16321633
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@ protected function createContainer(array $data = array())
10451045
'kernel.name' => 'kernel',
10461046
'kernel.root_dir' => __DIR__,
10471047
'kernel.container_class' => 'testContainer',
1048+
'container.build_hash' => 'Abc1234',
1049+
'container.build_id' => hash('crc32', 'Abc123423456789'),
1050+
'container.build_time' => 23456789,
10481051
), $data)));
10491052
}
10501053

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ext-xml": "*",
2121
"symfony/cache": "~3.4|~4.0",
2222
"symfony/class-loader": "~3.2",
23-
"symfony/dependency-injection": "~3.4|~4.0",
23+
"symfony/dependency-injection": "^3.4.3|^4.0.3",
2424
"symfony/config": "~3.4|~4.0",
2525
"symfony/event-dispatcher": "~3.4|~4.0",
2626
"symfony/http-foundation": "^3.3.11|~4.0",

0 commit comments

Comments
 (0)