| Description | After a database update with the CLI (php application/commands/console.php updatedb), the web side can keep using the OLD table schema from its cache for up to 1 hour. During this time, admin pages show "500 Database error".
This is a minor issue: it fixes itself after the cache expires, and deleting the cache fixes it at once. But right after an update, it looks like the update has failed, and an admin may restore the DB or run the update again.
I found this while testing for 20771 (it is the second "related problem" at the end of that report).
Cause
application/commands/console.php defines YII_DEBUG as true. So in the CLI, the cache component is CDummyCache (application/config/internal.php, around line 192).
- At the end of the update,
$oDB->schema->refresh() and Yii::app()->cache->flush() (in updatedb_helper.php) only clear this dummy cache. The web uses CFileCache in tmp/runtime/cache, and these files are not touched.
- The web caches the table schema for 3600 seconds (
schemaCachingDuration).
- If a web page is opened while the DB is still old (for example the "database update is already in progress" page), the old schema is written to the web cache. After the CLI update ends, the web still uses it.
What we saw (6.17.19 -> 7.3.0)
- On
/index.php/dashboard/view: CException: Property "Survey.preselectnoanswer" is not defined (SurveysGroupsettings.php)
- Right after login:
CDbException: Unknown column 'survey.nokeyboard'
- The cache file for the
lime_surveys schema still had nokeyboard (removed by Update_702) and did not have preselectnoanswer (added by Update_712). Its time matched the moment we opened the "update in progress" page.
- With
debug = 1 (no cache), the error went away. With debug = 0, it came back. After deleting tmp/runtime/cache/*, it was fixed at once.
- The same code is still in 7.5.1 and master (
console.php, internal.php, updatedb_helper.php). updatedb_helper.php even has the comment "Try to clear tmp/runtime (database cache files)" before Yii::app()->cache->flush(), but in the CLI this only flushes CDummyCache.
Workaround
Delete tmp/runtime/cache/* manually after a CLI update. We now do this in our update procedure.
Idea for a fix
After a successful CLI update, also clear the web cache (tmp/runtime/cache), for example by flushing a CFileCache instance for that directory.
Environment
LimeSurvey 7.3.0 (build 260922) / MariaDB 10.5.26 / PHP 8.2.33 / Linux (shared hosting) |
|---|
| Steps To Reproduce |
- Use an old version (we used 6.17.19) with some surveys. Make sure
config.php has debug = 0.
- Replace the files with the new version (we used 7.3.0). Do not open the web yet.
- Start the CLI update:
php application/commands/console.php updatedb
- While the CLI update is running, open any admin page in the browser. It shows "The database update is already in progress ..." (the update lock works). At this moment, the old schema is written to
tmp/runtime/cache.
- After the CLI update has finished, reload the page, log in and open the dashboard.
Actual result
"500 Database error" (Unknown column 'survey.nokeyboard' / Property "Survey.preselectnoanswer" is not defined). It stays for up to 1 hour.
Expected result
The web uses the new schema right after the CLI update. |
|---|