fix(session): prevent modx_session table overflow (installer check + fallback GC)#16927
fix(session): prevent modx_session table overflow (installer check + fallback GC)#16927Ibochkarev wants to merge 2 commits intomodxcms:3.xfrom
Conversation
…fallback GC) - Installer: block install when session.gc_probability=0 and ini_set fails; pass/fail instead of warn - Installer: isSessionGcEnabled() helper; fail message with Ubuntu/Debian and PHP/issue links - modSessionHandler: tryFallbackGc() with interval-based throttling via cache - modSessionHandler: gc($max) uses $max for interface compliance, fallback to gcMaxLifetime - modSessionHandler: try-catch in tryFallbackGc so session still opens on GC failure - New settings: session_gc_fallback_enabled, session_gc_fallback_interval (transport + lexicon) Refs modxcms#16275, modxcms#775
|
This is invalid. PHP calls gc based on PHP ini settings. |
|
@opengeek Hi! Can we leave comments in the ones indicated in the description of the Pr issue and close them? |
That is what I have been suggesting. Researching and/or commenting in issues to explore if there is a good solution to pursue an implementation of in this space before submitting PRs would be much more helpful. Increasing the cognitive workload by brute forcing a solution on an issue that was previously identified as not a bug in many places is not helpful. What WOULD be helpful is researching/commenting on/managing issues you are using to create these PRs. In this way we can bring attention to them and encourage collaborative discussions from all stakeholders. Identifying the merit of the issue is much easier without integrators being asked to explore an implementation which attempts to address said issue. |
What does it do?
isSessionGcEnabled(); uses pass when PHP session GC is enabled (orini_set('session.gc_probability', 1)succeeds), fail otherwise. Fail message includes instructions for Ubuntu/Debian, links to PHP session configuration and Ubuntu bug #316441, and notes that MODX will still clean sessions via built-in fallback when that option is enabled.tryFallbackGc()— runs session GC periodically (throttled bysession_gc_fallback_intervalvia cache) when PHP never callsgc()(e.g.session.gc_probability = 0on Ubuntu/Debian). Called fromopen(). On failure, errors are logged and not rethrown so the session still opens.$maxparameter for interface compliance (fallback togcMaxLifetimewhen$max <= 0). Returns(int)count orfalse; PHPDoc@return int|false. No union return type in signature (PHP 7.4 compatible).session_gc_fallback_enabled(boolean, default true),session_gc_fallback_interval(seconds, default 3600). Transport and English lexicon added. Lexicon notes that throttling uses cache and fallback does not run when cache is unavailable.Why is it needed?
The
modx_sessiontable can grow without bound (e.g. to gigabytes) when PHP never invokes the session handler’sgc()— commonly on Ubuntu/Debian wheresession.gc_probability = 0by default (see issue #775). Not all hostings allow changing php.ini. This change (1) makes the installer fail clearly when GC is disabled and not fixable viaini_set, with guidance and links, and (2) adds a built-in fallback that runs GC at a configurable interval so the session table is still cleaned even when PHP never callsgc().How to test
session.gc_probability = 0(andini_setdisabled if possible). Confirm the session GC step fails with the new message (Ubuntu/Debian, php.ini, links). Setsession.gc_probability = 1in php.ini (or allowini_set) and confirm the step passes.session_handler_class=modSessionHandler). Setsession_gc_fallback_intervalto a small value (e.g. 60). Ensure cache is available. Create expired session rows (e.g. setaccessto old timestamp). Trigger requests that open a session; after the interval, expired rows should be removed. Confirm in logs that no errors occur when GC runs; if DB is unavailable during fallback GC, confirm error is logged and session still opens.gc($max), confirm that the lifetime used for deletion respects the passed$max(e.g. by inspecting behavior whensession.gc_maxlifetimediffers from MODXsession_gc_maxlifetime).Related issue(s)/PR(s)
session.gc_probability = 0, workaround script, docs).