Hi,

Recently I found an interesting problem. I use the module which call drupal_set_message inside hook_boot(). It works fine until you have some 404 requests for imagecache images.

Basically when there is a 404 then drupal gets invoked and imagecache will try to generate the image. In case it fails it will issue 404 header end will execute exit() after that.

On regular drupal page when you call drupal_set_message, it stores your message in $_SESSIONS variable and then later drupal_get_messages() gets called to retrieve messages for display. Also on this step drupal_get_messages() usually clears $_SESSION array:

From bootstrap.inc:

if ($clear_queue) {
   unset($_SESSION['messages']);
}

What happens on 404 request is that hook_boot() (and potentially other hooks) gets called, drupal_set_message() gets called and creates entry in $_SESSION array, but drupal_get_messages() never gets called because of exit() command from imagecache module (_imagecache_cache() function). It means that in the sessions handler include/sessions.inc the content of the $_SESSION will be saved (stored). As a result of it, we will get a duplicate message on the next page view, since hook_boot() will add one and the other one will be served from sessions storage (which is database by default).

If you have multiple 404s on the page, then you will get multiple duplicate messages.

I know that it's not the module fault if you have 404's on the page, but I think it would be nice to add some workaround just in case.

Maybe it make sense also to invoke exit hook before halting script execution so other modules can react on it.

I will provide a patch with simple workaround soon and would be glad to hear your suggestions.

CommentFileSizeAuthor
#1 1094136-duplicate-messages-404-D6.patch939 bytesgansbrest
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gansbrest’s picture

Issue tags: +404
FileSize
939 bytes

Here is the simple patch just to solve this problem.

fizk’s picture

Issue tags: -404 +ImageCache 2.x Todo

Marking as ImageCache 2.x Todo.

fizk’s picture

Status: Patch (to be ported) » Needs review