Multi repos, config and MyXQL

I have two repos, and just recently we switched to myxql from mariaex. Since then, when starting the application, the second repo errors out, and seems to use the IP address/hostname of the machine network I am instead of what is supplied in the config.

Surely, there is a tiny mistake I am overlooking, but it is driving me mad.

As a first hint: how would ecto/myxql be able to get a hold of that ip?

For instance, on my local machine, it goes ahead and fetches my public ip (behind ISP router here). Or for the actual app running docker, it has the public IP of the host machine, instead of the actual DB host ip, as configured in the settings. The settings itself seem to be OK, we inspected the sys.config file inside the docker container.

Maybe our supervision tree for the application is not ok, but it worked just fine with mariaex.

    children = [
      # Start the Ecto repository
      supervisor(App.Repo, []),
      supervisor(App.RepoDuo, []),
      # Start the endpoint when the application starts
      supervisor(App.Endpoint, []),

So both repos use myxql but only the 2nd repo has problems? Could you paste your repos config? Whats the exact issue, its trying to connect to a host that it shouldn’t?

and if you have any additional repo config in its init/2 callback, please paste that too.

Hard to give too much config away since it is a client project, but I think it is pretty basic. What truly boggles me is the ip address it is trying to connect to. As I said, when I run the release on my local machine, the external IP of my ISP is mentioned (something like ‘78-xxx-xxx-xxx.access.telenet.be’ and if I run it on the actual machine, it shows the public Digital Ocean box IP, instead of the one for the db, supplied by the config).

Both repos have this as a module:

defmodule App.Repo do
  require Logger

  use Ecto.Repo,
    otp_app: :app_name,
    adapter: Ecto.Adapters.MyXQL

  use Scrivener

  def init(_, opts) do
    Logger.info "Starting Repo"
    Logger.info "#{inspect(opts)}"
    {:ok, opts}
  end
end

Second:

defmodule App.RepoDuo do
  require Logger

  use Ecto.Repo,
    otp_app: :app_name,
    adapter: Ecto.Adapters.MyXQ

  use Scrivener

  def init(_, opts) do
    Logger.info "Starting RepoDuo"
    Logger.info "#{inspect(opts)}"
    {:ok, opts}
  end
end

Then in the config:

config :app_name, App.Repo,
  username: System.fetch_env!("DB_USER"),
  password: System.fetch_env!("DB_PASSWORD"),
  database: System.fetch_env!("DB_NAME"),
  hostname: System.fetch_env!("DB_HOST"),
  timeout: 30_000,
  pool_size: 15

config :app_name, App.RepoDuo,
  username: System.fetch_env!("DB_DUO_USER"),
  password: System.fetch_env!("DB_DUO_PASSWORD"),
  database: System.fetch_env!("DB_DUO_NAME"),
  hostname: System.fetch_env!("DB_DUO_HOST"),
  timeout: 30_000,
  pool_size: 15

Almost as soon as we start the app, we get:
MyXQL.Connection (#PID<0.2640.0>) failed to connect: ** (MyXQL.Error) (1045) (ER_ACCESS_DENIED_ERROR) Access denied for...

Where is the IP mentioned? In your logs from init callback? From the MySQL server error? Both? Are you setting db config in prod.exs or releases.exs? Are you building release with Elixir releases or distillery? What’s your ecto, ecto_sql, and myxql version?

I know it’s related to deployment but if you could build a project that reproduces this, Ill be happy to help.

Yes in the logs. I commented out the other repo from the supervisor and output the opts that get in to the init/2 callback of the repo. There it seems fine, but immediately after seeing the log file, the errors come:

[info] Starting RepoDuo
:supervisor
[info] [telemetry_prefix: [:app_name, :repo_duo], otp_app: :app_name, username: "usr", password: "pwd", database: "duo", hostname: "SOME_IP", timeout: 30000, pool_size: 15]
[debug] [:production@darius][Elixir.Quantum.JobBroadcaster] Loading Initial Jobs from Config
[debug] [:production@darius][Elixir.Quantum.ExecutionBroadcaster] Unknown last execution time, using now
[error] MyXQL.Connection (#PID<0.2606.0>) failed to connect: ** (MyXQL.Error) (1045) (ER_ACCESS_DENIED_ERROR) Access denied for user 'usr'@'ANOTHER_IP.access.telenet.be' (using password: YES)

Just curious: is the supervisor setup ok?

children = [
      # Start the Ecto repository
      supervisor(App.Repo, []),
      supervisor(App.RepoDuo, []),
      # Start the endpoint when the application starts
      supervisor(App.Endpoint, []),

Ok, we got it!

I knew it was going to be something silly, sorry to waste your time a bit. Our generated pwd for the db had a $ in it, and it had to be escaped (in the env file where we export it from). So dumb… but it works now! :nerd_face:

1 Like