Skip to content

Commit

Permalink
[IMP] base: restrict _gc_sessions to a single database
Browse files Browse the repository at this point in the history
Background
=========

Previously, _gc_sessions ran for all databases regardless of the active one. This could cause problems in SaaS environments with shared session storage across databases.

Change
======

We propose introducing a limitation within the _gc_sessions method. The method will now check for the presence of the ODOO_SKIP_GC_SESSIONS environment variable. If set, it skips the cleanup process. This behavior is typically desired in environments launched without a specified database. On the other hand, if the environment variable is not set, the method will likely assume a non-SaaS environment (e.g., on-premise or development) and continue with the regular cleanup process.

Impact
=====

Ensures isolated session management for individual databases in SaaS environments.
Maintains automatic cleanup for developers and on-premise users.
task-3716956

closes odoo#152880

Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
  • Loading branch information
joda-odoo committed Apr 23, 2024
1 parent 8991976 commit 2b27e1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions odoo/addons/base/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def routing_map(self, key=None):

@api.autovacuum
def _gc_sessions(self):
if os.getenv("ODOO_SKIP_GC_SESSIONS"):
return
http.root.session_store.vacuum(max_lifetime=http.get_session_max_inactivity(self.env))

@api.model
Expand Down
12 changes: 12 additions & 0 deletions odoo/addons/test_http/tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import os
import datetime
import json
import pytz
Expand Down Expand Up @@ -211,6 +212,17 @@ def check_session_attr(value):
for value in not_recommended_values:
self.assertEqual(check_session_attr(value), None)

@patch("odoo.http.root.session_store.vacuum")
def test_session8_gc_ignored_no_db_name(self, mock):
with patch.dict(os.environ, {'ODOO_SKIP_GC_SESSIONS': ''}):
self.env['ir.http']._gc_sessions()
mock.assert_called_once()

with patch.dict(os.environ, {'ODOO_SKIP_GC_SESSIONS': '1'}):
mock.reset_mock()
self.env['ir.http']._gc_sessions()
mock.assert_not_called()

class TestSessionStore(HttpCaseWithUserDemo):
def setUp(self):
super().setUp()
Expand Down

0 comments on commit 2b27e1b

Please sign in to comment.