# HG changeset patch # User Marcin Kuzminski # Date 2020-09-14 09:13:41 # Node ID 7bc1ace51b5516b402bb9b389d33a1e14d1b91a2 # Parent 8eb465320ee4f955f8e912a17e1a3b21070053d1 sessions: patch baker to take expire time for redis for auto session cleanup. diff --git a/pkgs/patches/beaker/patch-beaker-improved-redis-2.diff b/pkgs/patches/beaker/patch-beaker-improved-redis-2.diff new file mode 100644 --- /dev/null +++ b/pkgs/patches/beaker/patch-beaker-improved-redis-2.diff @@ -0,0 +1,18 @@ +diff -rup Beaker-1.9.1-orig/beaker/session.py Beaker-1.9.1/beaker/session.py +--- Beaker-1.9.1-orig/beaker/session.py 2020-04-10 10:23:04.000000000 +0200 ++++ Beaker-1.9.1/beaker/session.py 2020-04-10 10:23:34.000000000 +0200 +@@ -156,6 +156,14 @@ def __init__(self, request, id=None, invalidate_corrupt=False, + if timeout and not save_accessed_time: + raise BeakerException("timeout requires save_accessed_time") + self.timeout = timeout ++ # We want to pass timeout param to redis backend to support expiration of keys ++ # In future, I believe, we can use this param for memcached and mongo as well ++ if self.timeout is not None and self.type == 'ext:redis': ++ # The backend expiration should always be a bit longer (I decied to use 2 minutes) than the ++ # session expiration itself to prevent the case where the backend data expires while ++ # the session is being read (PR#153) ++ self.namespace_args['timeout'] = self.timeout + 60 * 2 ++ + self.save_atime = save_accessed_time + self.use_cookies = use_cookies + self.cookie_expires = cookie_expires \ No newline at end of file diff --git a/pkgs/patches/beaker/patch-beaker-improved-redis.diff b/pkgs/patches/beaker/patch-beaker-improved-redis.diff new file mode 100644 --- /dev/null +++ b/pkgs/patches/beaker/patch-beaker-improved-redis.diff @@ -0,0 +1,26 @@ +diff -rup Beaker-1.9.1-orig/beaker/ext/redisnm.py Beaker-1.9.1/beaker/ext/redisnm.py +--- Beaker-1.9.1-orig/beaker/ext/redisnm.py 2018-04-10 10:23:04.000000000 +0200 ++++ Beaker-1.9.1/beaker/ext/redisnm.py 2018-04-10 10:23:34.000000000 +0200 +@@ -30,9 +30,10 @@ class RedisNamespaceManager(NamespaceManager): + + clients = SyncDict() + +- def __init__(self, namespace, url, **kw): ++ def __init__(self, namespace, url, timeout=None, **kw): + super(RedisNamespaceManager, self).__init__(namespace) + self.lock_dir = None # Redis uses redis itself for locking. ++ self.timeout = timeout + + if redis is None: + raise RuntimeError('redis is not available') +@@ -68,6 +69,8 @@ def has_key(self, key): + + def set_value(self, key, value, expiretime=None): + value = pickle.dumps(value) ++ if expiretime is None and self.timeout is not None: ++ expiretime = self.timeout + if expiretime is not None: + self.client.setex(self._format_key(key), int(expiretime), value) + else: + + diff --git a/pkgs/python-packages-overrides.nix b/pkgs/python-packages-overrides.nix --- a/pkgs/python-packages-overrides.nix +++ b/pkgs/python-packages-overrides.nix @@ -32,6 +32,8 @@ self: super: { patches = [ ./patches/beaker/patch-beaker-lock-func-debug.diff ./patches/beaker/patch-beaker-metadata-reuse.diff + ./patches/beaker/patch-beaker-improved-redis.diff + ./patches/beaker/patch-beaker-improved-redis-2.diff ]; });