When I enable memcache-session.inc I get a problem with drupal_set_message()/drupal_get_messages(), which results in messages never being cleared. After a message has been set with drupal_set_message it is shown on all following pages using drupal_get_messages.

When I disable memcache-session.inc this issue disappears and it works as expected.

I have tried to track this down and it seems like the variable holding messages is cleared by unset($_SESSION['messages']) beeing executed, but on the next request the message is back in $_SESSION['messages']).

I am using memcache.inc and memcache-session.inc with the following config and versions:

memcache module for drupal: 6.x-1.1
PECL php memcache:          2.2.4
PHP:                        5.2.4
memcached:                  1.2.6

$conf = array(
  'cache_inc' => './sites/all/modules/memcache/memcache.inc',

  'session_inc' => './sites/all/modules/memcache/memcache-session.inc',

  'memcache_servers' => array('localhost:11211' => 'default',
                              'localhost:11212' => 'cluster2'),

  'memcache_bins' => array('cache' => 'default',
                           'cache_page' => 'default',
                           'session' => 'cluster2',
                           'users' => 'cluster2')
);

Comments

andreiashu’s picture

confirmed. same happens here. (fresh D6.8 - D6.9 install)

mmcdougall’s picture

See http://drupal.org/node/363651 . Try my fix by commenting out the second "if" statement in sess_write() like this:


function sess_write($key, $value) {
  global $user;

  // If the client doesn't have a session, and one isn't being created ($value),
  // do nothing. If session saving has been turned off, do nothing.
  // Cases 1a, 1c, and 2c are covered here.
  if ((empty($_COOKIE[session_name()]) && empty($value)) || !session_save_session()) {
    return TRUE;
  }

  // Prepare the information to be saved.
  $session = new stdClass;
  $session->sid = $key;
  $session->uid = $user->uid;
  $session->cache = isset($user->cache) ? $user->cache : '';
  $session->hostname = ip_address();
  $session->session = $value;
  $session->timestamp = time();

  // If this is an authenticated user, or there is something to save in the
  // session, write it to memcache. Cases 1b, 2a, and 2b are covered here.
  //if ($user->uid || !empty($value)) {
    dmemcache_set($key, $session, ini_get('session.gc_maxlifetime'), 'session');
    if ($user->uid && $session->timestamp - $user->access > variable_get('session_write_interval', 360)) {
      db_query('UPDATE {users} SET access = %d WHERE uid = %d', $session->timestamp, $user->uid);
      // Update the user access time so that the dmemcache_set() call
      // caches the updated time.
      $user->access = $session->timestamp;
    }
    dmemcache_set($user->uid, $user, ini_get('session.gc_maxlifetime'), 'users');
  //}

  return TRUE;
}

Good luck, Marc

jvandyk’s picture

Status: Active » Needs review
StatusFileSize
new3.17 KB

Here is a patch based on Marc's observations.

jvandyk’s picture

StatusFileSize
new3.22 KB

And it occurs to me that it is cleanest to unset the session_data_present_at_load flag from $user prior to storage as well.

andreiashu’s picture

Applied the patch from #4. Everything seems to be working fine: drupal messages are being cleared and everything else works as expected.

jvandyk’s picture

Status: Needs review » Fixed

Committed. Fixed in 6.x-1.2 and later.

andreiashu’s picture

thanks !

jeremy’s picture

Version: 6.x-1.1 » 5.x-1.x-dev
Assigned: Unassigned » jeremy
Status: Fixed » Active

This fix needs to be backported to 5.x-1.x-dev.

jeremy’s picture

Status: Active » Needs review
StatusFileSize
new2.63 KB

Here is a first attempt at a backport. Testers welcome!

catch’s picture

Status: Needs review » Closed (won't fix)

Just marked 5.x as unsupported, so won't fixing this.