diff --git a/core/modules/image/image.module b/core/modules/image/image.module index c876bed..f2d4d86 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -586,19 +586,51 @@ function image_style_deliver($style, $scheme) { $success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri); if (!empty($lock_acquired)) { + // Do not release the lock until the file exists. Wait up to 1 second. + $counter = 0; + do { + if (file_exists($derivative_uri)) { + $success = TRUE; + break; + } + else { + $success = FALSE; + $counter++; + // Sleep for 100ms to allow for the file to appear on slow file systems. + usleep(100000); + } + } while ($counter < 10); + + // Release the lock. lock()->release($lock_name); } if ($success) { - $image = image_load($derivative_uri); - $uri = $image->source; - $headers = array( - 'Content-Type' => $image->info['mime_type'], - 'Content-Length' => $image->info['file_size'], - ); - return new BinaryFileResponse($uri, 200, $headers); + $image = FALSE; + $counter = 0; + // On certain file systems the image may not be available to be loaded + // eventhough we got a response of success. If that is the case we attempt + // to retrieve the image multiple times and issue an error if we have no + // image to transfer. Wait up to 1 second. + do { + $image = image_load($derivative_uri); + if (!empty($image)) { + $uri = $image->source; + $headers = array( + 'Content-Type' => $image->info['mime_type'], + 'Content-Length' => $image->info['file_size'], + ); + return new BinaryFileResponse($uri, 200, $headers); + } + else { + $counter++; + // Sleep for 100ms to allow for the file to appear on slow file + //systems. + usleep(100000); + } + } while ($counter < 10); } - else { + if (empty($image)) { watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri)); return new Response(t('Error generating image.'), 500); }