From 7bdaa49e3d1e78228c6c309d17daf48f1aa03523 Mon Sep 17 00:00:00 2001 From: Yann Gravrand Date: Tue, 1 Sep 2015 21:11:48 +0200 Subject: [PATCH] Added a warning when memcached client fails to store values too large --- nagare/sessions/memcached_sessions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nagare/sessions/memcached_sessions.py b/nagare/sessions/memcached_sessions.py index 6fcc4e7..a23aa91 100644 --- a/nagare/sessions/memcached_sessions.py +++ b/nagare/sessions/memcached_sessions.py @@ -11,7 +11,7 @@ import memcache -from nagare import local +from nagare import local, log from nagare.sessions import ExpirationError, common from nagare.sessions.serializer import Pickle @@ -221,7 +221,14 @@ def store_state(self, session_id, state_id, secure_id, use_same_state, session_d if not use_same_state: self._get_connection().incr((KEY_PREFIX + 'state') % session_id) - self._get_connection().set_multi({ + failures = self._get_connection().set_multi({ 'sess': (secure_id, session_data), '%05d' % state_id: state_data }, self.ttl, KEY_PREFIX % session_id, self.min_compress_len) + if failures: + # Log and fail early + log.error( + 'Failed to store keys %r in memcached, please check the size of your session or state (must be < %s bytes)' % ( + failures, + self._get_connection().server_max_value_length)) + raise ExpirationError() # FIXME: Create a new exception type?