Skip to content
Snippets Groups Projects
Commit 2690c63d authored by catch's avatar catch
Browse files

Issue #3211936 by alexpott, daffie: Race condition when generating sub directories for image styles

parent a9560b32
No related branches found
No related tags found
26 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!825Issue #3211838 by mondrake, longwave: Convert assertions involving use of...,!795Issue #3212005 by guilhermevp, tedbow, phenaproxima: Add @throws docs to...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!748#1091852 Display Bug when using #states (Forms API) with Ajax Request,!731Add a new recipe to Umami demo - Chicken souvlaki and couscous,!730Issue #3211810 by alexpott, xjm, Spokje, Amber Himes Matz, Kristen Pol,...,!700Issue #3185165 by Spokje, vipin.mittal18, Suresh Prabhu Parkala, lauriii,...,!594Put each entity type table into a details element on admin/config/regional/content-language,!592Issue #2957953: Editing menus user-experience has regressed,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -214,7 +214,10 @@ public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
$recursive_path .= $component;
if (!file_exists($recursive_path)) {
if (!$this->mkdirCall($recursive_path, $mode, FALSE, $context)) {
$success = $this->mkdirCall($recursive_path, $mode, FALSE, $context);
// If the operation failed, check again if the directory was created
// by another process/server, only report a failure if not.
if (!$success && !file_exists($recursive_path)) {
return FALSE;
}
// Not necessary to use self::chmod() as there is no scheme.
......
......@@ -5,6 +5,7 @@
use Drupal\Component\FileSecurity\FileSecurity;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
......@@ -196,4 +197,51 @@ public function testDirectoryCreation() {
$this->assertTrue($file_system->mkdir($dir . '/foo/baz/', 0775, TRUE));
}
/**
* Tests asynchronous directory creation.
*
* Image style generation can result in many calls to create similar directory
* paths. This test forks the process to create the same situation.
*/
public function testMultiplePrepareDirectory() {
if (!function_exists('pcntl_fork')) {
$this->markTestSkipped('Requires the pcntl_fork() function');
}
$directories = [];
for ($i = 1; $i <= 10; $i++) {
$directories[] = 'public://a/b/c/d/e/f/g/h/' . $i;
}
$file_system = $this->container->get('file_system');
$time_to_start = microtime(TRUE) + 0.1;
// This loop creates a new fork to create each directory.
foreach ($directories as $directory) {
$pid = pcntl_fork();
if ($pid == -1) {
$this->fail("Error forking");
}
elseif ($pid == 0) {
// Sleep so that all the forks start preparing the directory at the same
// time.
usleep(($time_to_start - microtime(TRUE)) * 1000000);
$file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
exit();
}
}
// This while loop holds the parent process until all the child threads
// are complete - at which point the script continues to execute.
while (pcntl_waitpid(0, $status) != -1);
foreach ($directories as $directory) {
$this->assertDirectoryExists($directory);
}
// Remove the database connection because it will have been destroyed when
// the forks exited. This allows
// \Drupal\KernelTests\KernelTestBase::tearDown() to reopen it.
Database::removeConnection('default');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment