litespeedtech / lscache_prestashop

LiteSpeed Cache Plugin for Prestashop
GNU General Public License v3.0
26 stars 16 forks source link

PHP Fatal error: Uncaught Error: Call to a member function query() #44

Closed elnarvi closed 1 year ago

elnarvi commented 3 years ago

It is very unstable, it generates 500 random errors, problem detected in Prestashop 1.6.x and 1.7.x

` 2021-05-31 02:00:46.426075 [NOTICE] [11712] [186.83.234.62:47870:HTTP2-65#APVH_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com:443] [STDERR] PHP Fatal error: Uncaught Error: Call to a member function query() on null in /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/DbPDO.php:165 Stack trace:

0 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(376): DbPDOCore->_query('\n\t\t\tSELECT `iso...')

1 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(663): DbCore->query('\n\t\t\tSELECT `iso...')

2 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(697): DbCore->getRow('\n\t\t\tSELECT `iso...', true)

3 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/Country.php(274): DbCore->getValue('\n\t\t\tSELECT `iso...')

4 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(234): CountryCore::getIsoById(6)

5 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(76): LiteSpee in /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/DbPDO.php on line

165 2021-05-31 02:04:15.721202 [NOTICE] [11712] [66.249.66.77:38770-2#APVH_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com:443] [STDERR] PHP Fatal error: Uncaught Error: Call to a member function query() on null in /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/DbPDO.php:165 Stack trace:

0 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(376): DbPDOCore->_query('\n\t\t\tSELECT `iso...')

1 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(663): DbCore->query('\n\t\t\tSELECT `iso...')

2 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/Db.php(697): DbCore->getRow('\n\t\t\tSELECT `iso...', true)

3 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/Country.php(274): DbCore->getValue('\n\t\t\tSELECT `iso...')

4 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(234): CountryCore::getIsoById(6)

5 /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(76): LiteSpee in /var/www/vhosts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com/httpdocs/classes/db/DbPDO.php on line

165

`

tonimarmol commented 2 years ago

@elnarvi did you fix this issue?

Eseperio commented 2 years ago

Issue is a huge problem. Losing lot of sales

tonimarmol commented 2 years ago

I migrated from Nginx to OpenLiteSpeed and I had to roll back.

Could it be some incompatibility with PHP 7.1? I am still using Prestashop 1.6 and I am forced to use PHP 7.1.

I want to try updating Prestashop manually with a code seen on your Github https://github.com/PrestaShop/PrestaShop-1.6/issues/3 so it can work with PHP 7.2 and test OLS again with the cache plugin.

Eseperio commented 2 years ago

It looks like a race condition caused by how LSPHP handles code. The __destruct method of Db connection object is called before other classes which are dependand of this.

Eseperio commented 2 years ago

In order to improve issue readability, i post the code formatted here:

 PHP Fatal error:  Uncaught Error: Call to a member function query() on null in /var/www/vhosts/domain.com/httpdocs/classes/db/DbPDO.php:165
Stack trace:
#0 /var/www/vhosts/domain.com/httpdocs/classes/db/Db.php(376): DbPDOCore->_query('\n\t\t\t\tSELECT COU...')
#1 /var/www/vhosts/domain.com/httpdocs/classes/db/Db.php(663): DbCore->query('\n\t\t\t\tSELECT COU...')
#2 /var/www/vhosts/domain.com/httpdocs/classes/db/Db.php(697): DbCore->getRow('\n\t\t\t\tSELECT COU...', true)
#3 /var/www/vhosts/domain.com/httpdocs/classes/Language.php(1123): DbCore->getValue('\n\t\t\t\tSELECT COU...')
#4 /var/www/vhosts/domain.com/httpdocs/classes/Language.php(1334): LanguageCore::countActiveLanguages(0)
#5 /var/www/vhosts/domain.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(245): LanguageCore::isMultiLanguageActivated()
#6 /var/www/vhosts/domain.com/httpdocs/modules/litespeedcache/classes/VaryCookie.php(76): LiteSpeedCacheVaryCookie->init(Object(Context), Object(Cookie))
 in /var/www/vhosts/domain.com/httpdocs/classes/db/DbPDO.php on line 165
Eseperio commented 2 years ago

Important Previous error and the one in the first message are not the same, but they have the same origin. They are all related with calls on cookie after db destruction, which is a thing that Prestashop contributors addressed here

Temp solution In Litespeed for Prestashop module configuration, in Context Vary bypass, add the following depending on your error:

Error includes reference to Bypass param
LanguageCore::countActiveLanguages lang
GetIsoById ctry
Currency curr
therampagerado commented 1 year ago

@Eseperio can you please elaborate how to apply this workaround?

I started seing 500 on all my FO pages and google brought me here. Is there a fix for this issue already?

php 7.4 cache module 1.4 Thirtybees

Edit: managed to find out. Now it's working again.

Varindien commented 1 year ago

Hello @therampagerado ,

you need to install litespeed module for prestashop and parameters provided by @Eseperio

litespeedtech commented 1 year ago

vary by "ctry" is removed, should no longer hit this error.