J3 Issue ?
avatar simbus82
simbus82
12 Sep 2019

Steps to reproduce the issue

  • Enable Redis cache in Global Configuration.
  • Use a socket: /var/run/redis/redis_6379.sock
  • Set port = 0

Expected result

Redis cache works as expected

Actual result

Error: Invalid field: Redis Server Port
Error: Redis connection failed

Cache is not working.

In the xml, the field for port is limited to 1


It should be 0.

With Error Reporting enabled, i see this:
Notice: Undefined variable: connection in /home/lormar/public_html/libraries/src/Cache/Storage/RedisStorage.php on line 106

In System Debug i have:

Redis connection failed
Call stack
#	Function	Location
1	JError::raise()	JROOT/libraries/legacy/error/error.php:299
2	JError::raiseWarning()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:113
3	Joomla\CMS\Cache\Storage\RedisStorage->getConnection()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:52
4	Joomla\CMS\Cache\Storage\RedisStorage->__construct()	JROOT/libraries/src/Cache/CacheStorage.php:185
5	Joomla\CMS\Cache\CacheStorage::getInstance()	JROOT/libraries/src/Cache/Cache.php:500
6	Joomla\CMS\Cache\Cache->_getStorage()	JROOT/libraries/src/Cache/Cache.php:223
7	Joomla\CMS\Cache\Cache->get()	JROOT/libraries/src/Cache/Controller/CallbackController.php:94
8	Joomla\CMS\Cache\Controller\CallbackController->get()	JROOT/libraries/src/Component/ComponentHelper.php:453
9	Joomla\CMS\Component\ComponentHelper::load()	JROOT/libraries/src/Component/ComponentHelper.php:519
10	Joomla\CMS\Component\ComponentHelper::getComponents()	JROOT/libraries/src/Component/ComponentHelper.php:44
11	Joomla\CMS\Component\ComponentHelper::getComponent()	JROOT/libraries/src/Component/ComponentHelper.php:103
12	Joomla\CMS\Component\ComponentHelper::getParams()	JROOT/libraries/src/Access/Access.php:939
13	Joomla\CMS\Access\Access::getGroupsByUser()	JROOT/libraries/src/Access/Access.php:1095
14	Joomla\CMS\Access\Access::getAuthorisedViewLevels()	JROOT/libraries/src/User/User.php:458
15	Joomla\CMS\User\User->getAuthorisedViewLevels()	JROOT/libraries/src/Plugin/PluginHelper.php:321
16	Joomla\CMS\Plugin\PluginHelper::load()	JROOT/libraries/src/Plugin/PluginHelper.php:87
17	Joomla\CMS\Plugin\PluginHelper::getPlugin()	JROOT/libraries/src/Plugin/PluginHelper.php:129
18	Joomla\CMS\Plugin\PluginHelper::isEnabled()	JROOT/libraries/src/Application/CMSApplication.php:612
19	Joomla\CMS\Application\CMSApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:301
20	Joomla\CMS\Application\AdministratorApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:123
21	Joomla\CMS\Application\AdministratorApplication->doExecute()	JROOT/libraries/src/Application/CMSApplication.php:196
22	Joomla\CMS\Application\CMSApplication->execute()	JROOT/administrator/index.php:51
Redis connection failed
Call stack
#	Function	Location
1	JError::raise()	JROOT/libraries/legacy/error/error.php:299
2	JError::raiseWarning()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:113
3	Joomla\CMS\Cache\Storage\RedisStorage->getConnection()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:52
4	Joomla\CMS\Cache\Storage\RedisStorage->__construct()	JROOT/libraries/src/Cache/CacheStorage.php:185
5	Joomla\CMS\Cache\CacheStorage::getInstance()	JROOT/libraries/src/Cache/Cache.php:500
6	Joomla\CMS\Cache\Cache->_getStorage()	JROOT/libraries/src/Cache/Cache.php:223
7	Joomla\CMS\Cache\Cache->get()	JROOT/libraries/src/Cache/Controller/CallbackController.php:94
8	Joomla\CMS\Cache\Controller\CallbackController->get()	JROOT/libraries/src/Plugin/PluginHelper.php:359
9	Joomla\CMS\Plugin\PluginHelper::load()	JROOT/libraries/src/Plugin/PluginHelper.php:87
10	Joomla\CMS\Plugin\PluginHelper::getPlugin()	JROOT/libraries/src/Plugin/PluginHelper.php:129
11	Joomla\CMS\Plugin\PluginHelper::isEnabled()	JROOT/libraries/src/Application/CMSApplication.php:612
12	Joomla\CMS\Application\CMSApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:301
13	Joomla\CMS\Application\AdministratorApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:123
14	Joomla\CMS\Application\AdministratorApplication->doExecute()	JROOT/libraries/src/Application/CMSApplication.php:196
15	Joomla\CMS\Application\CMSApplication->execute()	JROOT/administrator/index.php:51
Redis connection failed
Call stack
#	Function	Location
1	JError::raise()	JROOT/libraries/legacy/error/error.php:299
2	JError::raiseWarning()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:113
3	Joomla\CMS\Cache\Storage\RedisStorage->getConnection()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:52
4	Joomla\CMS\Cache\Storage\RedisStorage->__construct()	JROOT/libraries/src/Cache/CacheStorage.php:185
5	Joomla\CMS\Cache\CacheStorage::getInstance()	JROOT/libraries/src/Cache/Cache.php:500
6	Joomla\CMS\Cache\Cache->_getStorage()	JROOT/libraries/src/Cache/Cache.php:200
7	Joomla\CMS\Cache\Cache->contains()	 
8	call_user_func_array()	JROOT/libraries/src/Cache/CacheController.php:71
9	Joomla\CMS\Cache\CacheController->__call()	JROOT/libraries/src/Language/LanguageHelper.php:136
10	Joomla\CMS\Language\LanguageHelper::getLanguages()	JROOT/plugins/system/languagefilter/languagefilter.php:96
11	PlgSystemLanguageFilter->__construct()	JROOT/libraries/src/Plugin/PluginHelper.php:283
12	Joomla\CMS\Plugin\PluginHelper::import()	JROOT/libraries/src/Plugin/PluginHelper.php:182
13	Joomla\CMS\Plugin\PluginHelper::importPlugin()	JROOT/libraries/src/Application/CMSApplication.php:625
14	Joomla\CMS\Application\CMSApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:301
15	Joomla\CMS\Application\AdministratorApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:123
16	Joomla\CMS\Application\AdministratorApplication->doExecute()	JROOT/libraries/src/Application/CMSApplication.php:196
17	Joomla\CMS\Application\CMSApplication->execute()	JROOT/administrator/index.php:51
Redis connection failed
Call stack
#	Function	Location
1	JError::raise()	JROOT/libraries/legacy/error/error.php:299
2	JError::raiseWarning()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:113
3	Joomla\CMS\Cache\Storage\RedisStorage->getConnection()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:52
4	Joomla\CMS\Cache\Storage\RedisStorage->__construct()	JROOT/libraries/src/Cache/CacheStorage.php:185
5	Joomla\CMS\Cache\CacheStorage::getInstance()	JROOT/libraries/src/Cache/Cache.php:500
6	Joomla\CMS\Cache\Cache->_getStorage()	JROOT/libraries/src/Cache/Cache.php:223
7	Joomla\CMS\Cache\Cache->get()	JROOT/libraries/src/Cache/Controller/CallbackController.php:94
8	Joomla\CMS\Cache\Controller\CallbackController->get()	JROOT/libraries/src/Menu/SiteMenu.php:101
9	Joomla\CMS\Menu\SiteMenu->load()	JROOT/libraries/src/Menu/AbstractMenu.php:76
10	Joomla\CMS\Menu\AbstractMenu->__construct()	JROOT/libraries/src/Menu/SiteMenu.php:62
11	Joomla\CMS\Menu\SiteMenu->__construct()	JROOT/libraries/src/Menu/AbstractMenu.php:131
12	Joomla\CMS\Menu\AbstractMenu::getInstance()	JROOT/libraries/src/Application/CMSApplication.php:375
13	Joomla\CMS\Application\CMSApplication->getMenu()	JROOT/libraries/src/Application/SiteApplication.php:275
14	Joomla\CMS\Application\SiteApplication->getMenu()	JROOT/libraries/src/Router/SiteRouter.php:64
15	Joomla\CMS\Router\SiteRouter->__construct()	JROOT/libraries/src/Router/Router.php:189
16	Joomla\CMS\Router\Router::getInstance()	JROOT/libraries/src/Application/CMSApplication.php:491
17	Joomla\CMS\Application\CMSApplication::getRouter()	JROOT/libraries/src/Application/SiteApplication.php:403
18	Joomla\CMS\Application\SiteApplication::getRouter()	JROOT/plugins/system/languagefilter/languagefilter.php:145
19	PlgSystemLanguageFilter->onAfterInitialise()	JROOT/libraries/joomla/event/event.php:70
20	JEvent->update()	JROOT/libraries/joomla/event/dispatcher.php:160
21	JEventDispatcher->trigger()	JROOT/libraries/src/Application/BaseApplication.php:108
22	Joomla\CMS\Application\BaseApplication->triggerEvent()	JROOT/libraries/src/Application/CMSApplication.php:626
23	Joomla\CMS\Application\CMSApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:301
24	Joomla\CMS\Application\AdministratorApplication->initialiseApp()	JROOT/libraries/src/Application/AdministratorApplication.php:123
25	Joomla\CMS\Application\AdministratorApplication->doExecute()	JROOT/libraries/src/Application/CMSApplication.php:196
26	Joomla\CMS\Application\CMSApplication->execute()	JROOT/administrator/index.php:51
Redis connection failed
Call stack
#	Function	Location
1	JError::raise()	JROOT/libraries/legacy/error/error.php:299
2	JError::raiseWarning()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:113
3	Joomla\CMS\Cache\Storage\RedisStorage->getConnection()	JROOT/libraries/src/Cache/Storage/RedisStorage.php:52
4	Joomla\CMS\Cache\Storage\RedisStorage->__construct()	JROOT/libraries/src/Cache/CacheStorage.php:185
5	Joomla\CMS\Cache\CacheStorage::getInstance()	JROOT/libraries/src/Cache/Cache.php:500
6	Joomla\CMS\Cache\Cache->_getStorage()	JROOT/libraries/src/Cache/Cache.php:223
7	Joomla\CMS\Cache\Cache->get()	JROOT/libraries/src/Cache/Controller/CallbackController.php:94
8	Joomla\CMS\Cache\Controller\CallbackController->get()	JROOT/libraries/src/Helper/ModuleHelper.php:432
9	Joomla\CMS\Helper\ModuleHelper::getModuleList()	JROOT/libraries/src/Helper/ModuleHelper.php:362
10	Joomla\CMS\Helper\ModuleHelper::load()	JROOT/libraries/src/Helper/ModuleHelper.php:87
11	Joomla\CMS\Helper\ModuleHelper::getModules()	JROOT/administrator/components/com_config/view/application/tmpl/default.php:46
12	include()	JROOT/libraries/joomla/view/html.php:151
13	JViewHtml->render()	JROOT/administrator/components/com_config/view/application/html.php:79
14	ConfigViewApplicationHtml->render()	JROOT/components/com_config/controller/display.php:113
15	ConfigControllerDisplay->execute()	JROOT/administrator/components/com_config/config.php:31
16	require_once()	JROOT/libraries/src/Component/ComponentHelper.php:402
17	Joomla\CMS\Component\ComponentHelper::executeComponent()	JROOT/libraries/src/Component/ComponentHelper.php:377
18	Joomla\CMS\Component\ComponentHelper::renderComponent()	JROOT/libraries/src/Application/AdministratorApplication.php:101
19	Joomla\CMS\Application\AdministratorApplication->dispatch()	JROOT/libraries/src/Application/AdministratorApplication.php:159
20	Joomla\CMS\Application\AdministratorApplication->doExecute()	JROOT/libraries/src/Application/CMSApplication.php:196
21	Joomla\CMS\Application\CMSApplication->execute()	JROOT/administrator/index.php:51


System information (as much as possible)

PHP 7.2
J3.9.11
Redis 5.0.5 (redis.io)
phpredis 5.0.2 (PECL - CPanel)

Additional comments

host: /var/run/redis/redis_6379.sock
port: 0

Same settings in Magento 1.9.4.2 (that supports Redis natively) are working well (so it's not a server misconfiguration)

With:
host: localhost
port: 6379
... all is working well.

avatar simbus82 simbus82 - open - 12 Sep 2019
avatar joomla-cms-bot joomla-cms-bot - change - 12 Sep 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 12 Sep 2019
avatar simbus82 simbus82 - change - 12 Sep 2019
The description was changed
avatar simbus82 simbus82 - edited - 12 Sep 2019
avatar simbus82 simbus82 - change - 12 Sep 2019
The description was changed
avatar simbus82 simbus82 - edited - 12 Sep 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 12 Sep 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 12 Sep 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 12 Sep 2019
Title
[3.9.11] Redis Port can be 0 - Issues with Redis by Socket
Redis Port can be 0 - Issues with Redis by Socket
avatar franz-wohlkoenig franz-wohlkoenig - edited - 12 Sep 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 12 Sep 2019
Status New Discussion
avatar wilsonge
wilsonge - comment - 12 Sep 2019

IANA classifies port 0 as a reserved port https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml

This article suggests "Port 0 is a wildcard port that tells the system to find a suitable port number." (and various other google results :P)

Either way given it's reserved my gut feeling is that if Redis binds to this port it's a bug in redis rather than a bug in Joomla we can't connect to it

avatar HLeithner
HLeithner - comment - 12 Sep 2019

I think he only wants to bind to a unix socket and "0" is a workaround similar to my PR for memcache #24073

avatar simbus82
simbus82 - comment - 12 Sep 2019

Hi @wilsonge ,
i use Redis from many years in Magento, lot of time before Joomla use it.

Port 0 in Redis is a "standard" to say to Redis "plugins" to use the unix socket.
https://www.google.com/search?q=redis+unix+socket&oq=redis+unix+socket

When you switch to "unix://var/run/redis/redis.sock" there is no more port logic.

Here, the first problem is that we need to be allowed to add 0 in the port field.

Then i see in
joomla-cms/libraries/src/Cache/Storage/RedisStorage.php is missing the logic that use a UNIX socket like i see in joomla-cms/libraries/joomla/session/storage/redis.php

$path = 'unix://' . $this->_server['host'];

I don't understand why the "logic" of connection for Redis Cache have been written so differently than the code in Redis Session.

Am i wrong, or the connection logic to Redis should be uniform?

avatar PhilETaylor
PhilETaylor - comment - 14 May 2021

Significant work has been done in Joomla 4 to allow Redis to connect using a socket. This work was done by @csthomas in #18395

You can see here:

if ($server['host'][0] === '/')

That if the first character of your REDIS HOST is a slash / then Joomla will ignore the provided REDIS PORT and will set the port to 0

Also in the SessionFactory.php you can see that Joomla (WRONGLY!!!! - doesn't yet, but will after my PR) sets the port to 0 if the REDIS HOST starts with a /

$port = $host[0] === '/' ? $config->get('session_redis_server_port', 6379) : 6379;

Joomla then goes on to successfully make a redis connection using the sock.

Therefore you can safely IGNORE the port number in Joomla global config, and just provide any number - YOU DO NOT need to specify port 0.

avatar PhilETaylor
PhilETaylor - comment - 14 May 2021

PR to fix the wrong logic in SessionFactory is here #33880

This issue can now be closed.

avatar richard67 richard67 - change - 14 May 2021
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2021-05-14 20:42:40
Closed_By richard67
avatar richard67
richard67 - comment - 14 May 2021

Closing as having a pull request. Please test #33880 . Thanks in advance.

avatar richard67 richard67 - close - 14 May 2021
avatar Rakeshmvd
Rakeshmvd - comment - 26 Oct 2022

Still getting the
Notice: Undefined variable: connection in /home/lormar/public_html/libraries/src/Cache/Storage/RedisStorage.php on line 106
with J3

avatar richard67
richard67 - comment - 26 Oct 2022

Well I would not expect it to be fixed in J3 because the pull request was for J4. And as J3 is meanwhile in security only phase, it will not receive a fix for that anymore.

avatar cchosting
cchosting - comment - 13 Dec 2023

Any chance that this can be pushed to J5?

avatar brianteeman
brianteeman - comment - 13 Dec 2023

from what I can see it was fixed for Joomla 4 with #33880 so should be working with all supportyed versions now including j5

Add a Comment

Login with GitHub to post a comment