jeroenbourgois

jeroenbourgois

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, []),

Showing Posts 1 to 6

wojtekmach

wojtekmach

Hex Core Team

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?

wojtekmach

wojtekmach

Hex Core Team

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

jeroenbourgois

jeroenbourgois OP

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...

wojtekmach

wojtekmach

Hex Core Team

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.

jeroenbourgois

jeroenbourgois OP

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, []),
jeroenbourgois

jeroenbourgois OP

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:

— All posts loaded —

Where Next? Top

Trending in Questions Top

water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews