Expire sessions generated by health checks quickly

The default expiration of sessions is 7 days. With healthchecks run
every few seconds, we quickly have millions of anonymous sessions in
Redis. Allow to define a custom expiration for some sessions and set a
very short one for the monitoring requests.
This commit is contained in:
Guewen Baconnier authored and jcoux committed 2018-01-11 10:46:55 +01:00
1 parent 8eaa15df7b
commit 39e71ff334
2 files changed
+14 -2

No files matched your search

+9
View File
@@ -19,4 +19,13 @@ class Monitoring(http.Controller):
# queue job, cron, database, ...
headers = {'Content-Type': 'application/json'}
info = {'status': 1}
session = http.request.session
# We set a custom expiration of 1 second for this request, as we do a
# lot of health checks, we don't want those anonymous sessions to be
# kept. Beware, it works only when session_redis is used.
# Alternatively, we could set 'session.should_save = False', which is
# tested in odoo source code, but we wouldn't check the health of
# Redis.
if not session.uid:
session.expiration = 1
return werkzeug.wrappers.Response(json.dumps(info), headers=headers)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.