Haven't fully investigated this, but when, for some reason, the $src variable is empty, inside _imagecache_cache function, the consecutive requests for that image lead into a 307 redirect loop that some clients don't handle properly, thus the servers become hammered until they drop. Simple fix is adding a check for $src. Replace:
if (!is_file($src) && !is_file($src = file_create_path($src))) {
with
if (!$src || (!is_file($src) && !is_file($src = file_create_path($src)))) {
inside function _imagecache_cache in imagecache.module

Comments

BogdanN’s picture

Ok,

Further investigated. That was not the problem. The flow is like this:
1st request needs to generate a new image. It checks for a lock, doesn't find it, creates the lock and starts the generation. Further requests check for the lock, find it and issue a 307. All goes like this until the 1st request finishes generating the image. If for some reason the image generation fails, the lock is never deleted so anything that points to that image will get into a neverending 307 loop. That is fine with Firefox, for instance, but some other browsers/robots, etc. simply redirect endlessly until the servers go down.

The fix is to add: file_delete($lockfile); right before the last 3 lines of the _imagecache_cache function.

Mixologic’s picture

Awesome. You have save me a *ton* of time on this.

BogdanN’s picture

The fix above should do the trick, but sometimes even it is not enough, as the script might simply bail out due to extreme server load. To finally put an end to the never-ending loop problems, modify _imagecache_cache and replace:

if (file_exists($lockfile)) {
watchdog('imagecache', 'ImageCache already generating: %dst, Lock file: %tmp.', array('%dst' => $dst, '%tmp' => $lockfile), WATCHDOG_NOTICE);
// 307 Temporary Redirect, to myself. Lets hope the image is done next time around.
header('Location: '. request_uri(), TRUE, 307);
exit;
}

with:

if (file_exists($lockfile)) {
// prevent the loop for running more than 3 seconds. the pic will be created on the next request anyway, and by that time the server load would have dropped
if (time() - filemtime($lockfile) > 3) {
file_delete($lockfile);
} else {
watchdog('imagecache', 'ImageCache already generating: %dst, Lock file: %tmp.', array('%dst' => $dst, '%tmp' => $lockfile), WATCHDOG_NOTICE);
// 307 Temporary Redirect, to myself. Lets hope the image is done next time around.
header('Location: '. request_uri(), TRUE, 307);
exit;
}
}

ezra-g’s picture

Status: Active » Closed (duplicate)
bora-89’s picture

@Bogdan Nicolau
Thanks for you work!

eric constantinides’s picture

Version: 6.x-2.0-beta10 » 6.x-2.0-beta12

Worked like a charm BogdanN! Thanks so much!!

BetoAveiga’s picture

@BogdanN THANKS! :) I was having this problem for weeks! Thanks a lot for your help!!!! It works, in my opinion, it must be considered in the next release...

nd987’s picture

@BogdanN the man! The second, longer bit of code did the trick!