Cms: When `devMode => false` empty string password for Redis config shows "Service Unavailable Craft isn’t installed yet"

Created on 24 Feb 2021  ·  12Comments  ·  Source: craftcms/cms

Description

On prepping a site to go to production, I stumbled on a strange situation. With devMode => false the site produced an error: "Service Unavailable Craft isn’t installed yet." When trying to debug by setting devMode => true, the error went away and the site worked as expected.

Long story short, our host has set up Redis to not use a password internally and told us to leave the password blank. And having the password in the Redis config as an empty string with devMode on worked fine. But for whatever reason, when devMode is off, the password as a blank string for Redis config causes the "not installed" error. When removing the password key from the Redis config entirely, it magically started working with devMode off.

This was _very_ difficult to debug and track down. I would propose that the behavior should be the same whether devMode is on or off. If having the password present in the config results in a fatal error, it should do so whether devMode is enabled or not.

Steps to reproduce

  1. Set devMode => true
  2. Set up a Redis config that needs no password in a specific environment
  3. Add Redis config to Craft app.php config file
  4. Note that there are no errors with devMode on
  5. Now set devMode => false
  6. Note the error that Craft is not installed

Additional info

  • Craft version: 3.5.17.1
  • PHP version: 7.4.15
  • Database driver & version: MySQL 5.5.5
bug

Most helpful comment

So, specifically, the problem I was running into was the configuration in config/app.php. Specifically, the hosting company set up Redis and said leave password empty. So I left the password key in the config array as an empty string. No error was shown in devMode but when switching it off as we get closer to going live is where the error started showing up.

redis-with-empty-password-string

Removing the password key completely was the ticket. I tested several times. Adding the password key into the config resulted in the error _only when devMode was false_.

Screen Shot 2021-02-26 at 9 15 35 AM

But the site works with or without the empty string password when devMode is true.

To be completely clear, I totally get that an empty string is not the same as "does not exist" and why that key maybe shouldn't be there if you want to do Redis without a password. The behavior specifically that I think should be tracked down (if possible, this seems like a fun one 😝) is that there is no error in devMode. Only when devMode is false. Since there's no error in devMode, and since the error is super generic (and could even be considered wrong) when devMode is false, it's difficult to figure out where the error is coming from and what's causing it.

Obviously, based on @brandonkelly's comment about this being a Yii component outside the control of Craft, maybe there's nothing to be done here, but it is curious that it's happening in one mode and not the other. My main goal here is to spare anyone any pain related to this super obscure bug (if it is a bug) if possible 😃.

All 12 comments

@tjdraper Were you directly toggling the devMode value in config/general.php, or changing your environment name (e.g. the ENVIRONMENT environment variable)?

I would propose that the behavior should be the same whether devMode is on or off. If having the password present in the config results in a fatal error, it should do so whether devMode is enabled or not.

Craft doesn’t know anything about Redis – that functionality is entirely supplied by the yii2-redis package, which Craft does not directly require or care about/interfere with in any way. And obviously yii2-redis doesn’t know anything about Craft’s devMode config setting; nor does it care about YII_DEBUG (which gets set to 1 when running Craft in Dev Mode), save for one instance where it determines which error message to output.

So I’m at a loss of how toggling Dev Mode could have any affect on it, unless you were actually changing the environment name (which could potentially have other implications, depending on your config).

Ahh, fair point. After hours of debugging my poor brain did not remember I had installed a Yii component to configure for Redis.

I was toggling devMode directly. So it's still very… strange… particularly since, as you pointed out, the yii2-redis package is its own thing.

Curious…

Having a hard time trying to reproduce this locally, unfortunately.

Using the Redis example in the docs: https://craftcms.com/docs/3.x/config/#redis-example

I've tried these combos in the .env file:

REDIS_PASSWORD=
REDIS_PASSWORD=''
REDIS_PASSWORD=""

Tried them using an empty database, one with a fresh Craft install, with devMode both enabled and disabled, etc.

Can you think of anything I might be missing to replicate?

So, specifically, the problem I was running into was the configuration in config/app.php. Specifically, the hosting company set up Redis and said leave password empty. So I left the password key in the config array as an empty string. No error was shown in devMode but when switching it off as we get closer to going live is where the error started showing up.

redis-with-empty-password-string

Removing the password key completely was the ticket. I tested several times. Adding the password key into the config resulted in the error _only when devMode was false_.

Screen Shot 2021-02-26 at 9 15 35 AM

But the site works with or without the empty string password when devMode is true.

To be completely clear, I totally get that an empty string is not the same as "does not exist" and why that key maybe shouldn't be there if you want to do Redis without a password. The behavior specifically that I think should be tracked down (if possible, this seems like a fun one 😝) is that there is no error in devMode. Only when devMode is false. Since there's no error in devMode, and since the error is super generic (and could even be considered wrong) when devMode is false, it's difficult to figure out where the error is coming from and what's causing it.

Obviously, based on @brandonkelly's comment about this being a Yii component outside the control of Craft, maybe there's nothing to be done here, but it is curious that it's happening in one mode and not the other. My main goal here is to spare anyone any pain related to this super obscure bug (if it is a bug) if possible 😃.

Any chance we can get SSH access to the box, so we can investigate?

Hi all - unfortunately, this is client infrastructure we don't have permission to give access to. I definitely sympathize with not being able to replicate it and understand if this means you can't help/debug. I wish we could share it in this case.

We'll see if we can find time to play around with some Docker set up to see if we can replicate it!

We managed to reproduce the error using Forge! Looking into it.

Was fun to track down... this has been resolved in e18321039c1a20529d4b80db0d3adb0dd339bf88.

yii2-redis awkwardly throws yii\db\Exception's rather than their own exception class.

Nice. Fun times.

Craft 3.6.8 is out with that fix. Thanks for reporting and bearing with us!

So, specifically, the problem I was running into was the configuration in config/app.php. Specifically, the hosting company set up Redis and said leave password empty. So I left the password key in the config array as an empty string. No error was shown in devMode but when switching it off as we get closer to going live is where the error started showing up.

redis-with-empty-password-string

Removing the password key completely was the ticket. I tested several times. Adding the password key into the config resulted in the error _only when devMode was false_.

Screen Shot 2021-02-26 at 9 15 35 AM

But the site works with or without the empty string password when devMode is true.

To be completely clear, I totally get that an empty string is not the same as "does not exist" and why that key maybe shouldn't be there if you want to do Redis without a password. The behavior specifically that I think should be tracked down (if possible, this seems like a fun one 😝) is that there is no error in devMode. Only when devMode is false. Since there's no error in devMode, and since the error is super generic (and could even be considered wrong) when devMode is false, it's difficult to figure out where the error is coming from and what's causing it.

Obviously, based on @brandonkelly's comment about this being a Yii component outside the control of Craft, maybe there's nothing to be done here, but it is curious that it's happening in one mode and not the other. My main goal here is to spare anyone any pain related to this super obscure bug (if it is a bug) if possible 😃.

you saved my life. I had an empty password too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davist11 picture davist11  ·  3Comments

leigeber picture leigeber  ·  3Comments

angrybrad picture angrybrad  ·  3Comments

RitterKnightCreative picture RitterKnightCreative  ·  3Comments

lukebailey picture lukebailey  ·  3Comments