Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect to DB #7

Closed
Jimbo222 opened this issue Aug 5, 2024 · 4 comments
Closed

Not able to connect to DB #7

Jimbo222 opened this issue Aug 5, 2024 · 4 comments

Comments

@Jimbo222
Copy link

Jimbo222 commented Aug 5, 2024

Hi,

I have a similar issue to that mentioned in: #4

I am on HA ersion 2024.07.4
And using V0.5.8 of the addon.

I am using maria DB with the recorder url:

db_url: 'mysql://USER:SECRET@core-mariadb/homeassistant?charset=utf8mb4'

Extract of the logs:

[Nest] 175  - 08/05/2024, 11:22:18 PM     LOG [ConfigService] found and parsed secrets file
[Nest] 175  - 08/05/2024, 11:22:18 PM     LOG [ConfigService] 9 secrets found for file /homeassistant/service_account.json
[Nest] 175  - 08/05/2024, 11:22:18 PM     LOG [ConfigService] parsed config file
[Nest] 175  - 08/05/2024, 11:22:18 PM     LOG [ConfigService] found recorder config, gonna use it
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [NestFactory] Starting Nest application... +2048ms
[Nest] 175  - 08/05/2024, 11:22:20 PM   ERROR [TypeOrmModule] Unable to connect to the database (homeass). Retrying (1)...
URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at DriverUtils.parseConnectionUrl (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:156:23)
    at DriverUtils.buildDriverOptions (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:47:43)
    at new MysqlDriver (/usr/src/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:276:51)
    at DriverFactory.create (/usr/src/app/node_modules/typeorm/driver/DriverFactory.js:34:24)
    at new DataSource (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:56:59)
    at createTypeormDataSource (/usr/src/app/node_modules/@nestjs/typeorm/dist/typeorm-core.module.js:164:23)
    at /usr/src/app/node_modules/@nestjs/typeorm/dist/typeorm-core.module.js:169:36
    at Observable._subscribe (/usr/src/app/node_modules/rxjs/dist/cjs/internal/observable/defer.js:8:31)
    at Observable._trySubscribe (/usr/src/app/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] DatabaseModule dependencies initialized +25ms
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] ConfigHostModule dependencies initialized +2ms
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] ServeStaticModule dependencies initialized +1ms
[Nest] 175  - 08/05/2024, 11:22:20 PM     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms

In my configuration.yaml i am referencing the recorder settings using a secret:

recorder:
  db_url: !secret mariadb_url

Relevant content of the secrets.yaml:

mariadb_url: 'mysql://USER:SECRET@core-mariadb/homeassistant?charset=utf8mb4'

Is this a supported method or am I doing someting wrong here?

Thanks

@jehy
Copy link
Owner

jehy commented Mar 4, 2025

Hi! Sometimes plugin fails to correctly parse config files and secrets. Please try specifying connection string mysql://USER:SECRET@core-mariadb/homeassistant?charset=utf8mb4 in plugin options.

@Jimbo222
Copy link
Author

Jimbo222 commented Mar 4, 2025

Hi - I tried this also at the time but had the same result:
I was never able to get this to connect.

I tried it again with the latest version of the add-on and I get the below URI malformed error.

Just to confirm I entered the connection string in the addon config as below and it's exactly how I have it in my HA configuration which looks the same as you mentioned:
mysql://[usename]:[password]@core-mariadb/homeassistant?charset=utf8mb4

One thought - could it be an issue with special characters in the password? I do use non-alphanumeric characters.

I dont want to go playing with the passwords at that level on my main instance, so when I get a moment I may spin up another test instance to check with a simple password.

[22:30:38] INFO: Starting NGinx... [22:30:38] INFO: Starting dbstats... s6-rc: info: service legacy-services successfully started nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:62 2025/03/04 22:30:38 [notice] 177#177: using the "epoll" event method 2025/03/04 22:30:38 [notice] 177#177: nginx/1.24.0 2025/03/04 22:30:38 [notice] 177#177: OS: Linux 6.6.62-haos-raspi 2025/03/04 22:30:38 [notice] 177#177: getrlimit(RLIMIT_NOFILE): 1073741816:1073741816 2025/03/04 22:30:38 [notice] 177#177: start worker processes 2025/03/04 22:30:38 [notice] 177#177: start worker process 199 [Nest] 176 - 03/04/2025, 10:30:40 PM LOG [ConfigService] Using database options from env [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [NestFactory] Starting Nest application... +1416ms [Nest] 176 - 03/04/2025, 10:30:41 PM ERROR [TypeOrmModule] Unable to connect to the database (homeass). Retrying (1)... URIError: URI malformed at decodeURIComponent (<anonymous>) at DriverUtils.parseConnectionUrl (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:156:23) at DriverUtils.buildDriverOptions (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:47:43) at new MysqlDriver (/usr/src/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:276:51) at DriverFactory.create (/usr/src/app/node_modules/typeorm/driver/DriverFactory.js:34:24) at new DataSource (/usr/src/app/node_modules/typeorm/data-source/DataSource.js:56:59) at createTypeormDataSource (/usr/src/app/node_modules/@nestjs/typeorm/dist/typeorm-core.module.js:164:23) at /usr/src/app/node_modules/@nestjs/typeorm/dist/typeorm-core.module.js:169:36 at Observable._subscribe (/usr/src/app/node_modules/rxjs/dist/cjs/internal/observable/defer.js:8:31) at Observable._trySubscribe (/usr/src/app/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25) [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] DatabaseModule dependencies initialized +8ms [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] ConfigHostModule dependencies initialized +2ms [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] AppModule dependencies initialized +0ms [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] ServeStaticModule dependencies initialized +1ms [Nest] 176 - 03/04/2025, 10:30:41 PM LOG [InstanceLoader] ConfigModule dependencies initialized +1ms [Nest] 176 - 03/04/2025, 10:30:44 PM ERROR [TypeOrmModule] Unable to connect to the database (homeass). Retrying (2)... URIError: URI malformed at decodeURIComponent (<anonymous>) at DriverUtils.parseConnectionUrl (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:156:23) at DriverUtils.buildDriverOptions (/usr/src/app/node_modules/typeorm/driver/DriverUtils.js:47:43) at new MysqlDriver (/usr/src/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:276:51)

@jehy
Copy link
Owner

jehy commented Mar 4, 2025

Yeah, it looks like you are right - connection string should be a proper URL, and if it's not encoded,then parsing it as URL with fail, for example like in typeorm/typeorm#3716

So special chars like : @ should be masked.
You can press F12, open deveoper console, and enter encodeURIComponent("YOUR_PASSWORD_HERE") - in output you will get a password version that you should be able to use with my addon.

Seems like HA itself somehow works around this case, but it doesn't seem trivial. For example, if your connection string is

mysql://login:password_part1:password_part2@password_part3@core-mariadb/homeassistant?charset=utf8mb4 - then it's not quite clear, how to deal with it....

And it can be even

mysql://login_part1:login_part2@login_part_3:password_part1:password_part2@password_part3@core-mariadb/homeassistant?charset=utf8mb4

x_x

@Jimbo222
Copy link
Author

Jimbo222 commented Mar 4, 2025

Thanks for coming back to me with the info and suggestion.

I can confirm that special characters in the password is exactly the issue.
After using the encodeURIComponent function and updating the connection string the addon it started up without incident.

Thanks

@jehy jehy closed this as completed Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants