Session DB Writeback

fractile81 - April 22, 2009 - 16:52
Project:Memcache API and Integration
Version:6.x-1.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I've been testing the use of the Memcache session handling, and noticed that:

  1. There are no database writebacks for session information like there is for cache information.
  2. sess_destroy_uid(); is not implemented. Isn't that a security problem if a user is disabled while still logged in?

Perhaps there's a reasoning for this that I'm not able to see, but why shouldn't the session information be written back to the database? Is there a performance hit? If the writeback was there, it would be really easy to clear sessions by uid. I bring this up because I need to use the sess_destroy_uid(); function, but am unable to get my code to work when using Memcache session handling.

#1

matt_paz - April 22, 2009 - 17:25
Category:feature request» bug report

+1

#2

Jeremy - July 13, 2009 - 20:50
Status:active» needs review

The attached patch fixes this by looking up the memcache session by first retrieving the user object from memcache. It then uses this object to destroy the session. Please test.

AttachmentSize
memcache-session.inc_.patch 554 bytes

#3

Jeremy - July 13, 2009 - 21:25

Whoops -- the previous patch had a typo. This one should work. Please test.

AttachmentSize
memcache-session.inc_.patch 545 bytes

#4

Jeremy - July 14, 2009 - 18:39

There was a code path where the session id wasn't saved in the user object, causing the sess_destroy_uid() to fail. The attached patch is updated to fix this. It works in all my testing.

AttachmentSize
memcache-session.inc_.patch 1.01 KB

#5

Jeremy - July 14, 2009 - 22:07
Status:needs review» fixed

Committed.

#6

Jeremy - July 14, 2009 - 22:08

Link to the commit for reference:
http://drupal.org/cvs?commit=237454

#7

doq - July 20, 2009 - 14:02
Status:fixed» active

Only one user session (probably latest) gets deleted.

<?php
function sess_destroy_uid($uid) {
$user = dmemcache_get($uid, 'users');
+  if (
is_object($user) && isset($user->sid)) {
+   
dmemcache_delete($user->sid, 'session');
+  }
dmemcache_delete($uid, 'users');
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.