(Mariaex.Error) failed to upgraded socket: :enotconn

I’m running Ecto with mariaex, the database is on different server. And I’m using the ssl feature, here’s what I tried in prod.secret.exs:

config :app, App.Repo,
  adapter: Ecto.Adapters.MySQL,
  ssl: true,
  ssl_opts: [cacertfile: "ssl/ca.pem", certfile: "ssl/client-cert.pem", keyfile: "ssl/client-key.pem"]

Client keys sit in config/ssl folder with prod.secret.exs file.

When running migrate, I got these error:

Loading app..
Starting dependencies..
Starting repos..
Running migrations for app
02:49:40.250 [error] Mariaex.Protocol (#PID<0.96.0>) failed to connect: ** (Mariaex.Error) failed to upgraded socket: :enotconn
{"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.DBConnection.ConnectionError',message=><<"connection not available because of disconnection">>},[{'Elixir.DBConnection',checkout,2,[{file,"lib/db_connection.ex"},{line,718}]},{'Elixir.DBConnection',run,3,[{file,"lib/db_connection.ex"},{line,619}]},{'Elixir.DBConnection',run_meter,3,[{file,"lib/db_connection.ex"},{line,921}]},{'Elixir.DBConnection',prepare_execute,4,[{file,"lib/db_connection.ex"},{line,463}]},{'Elixir.Ecto.Adapters.MySQL.Connection',execute,4,[{file,"lib/ecto/adapters/mysql/connection.ex"},{line,32}]},{'Elixir.Ecto.Adapters.SQL',sql_call,6,[{file,"lib/ecto/adapters/sql.ex"},{line,235}]},{'Elixir.Ecto.Adapters.SQL','query!',5,[{file,"lib/ecto/adapters/sql.ex"},{line,185}]},{'Elixir.Ecto.Adapters.MySQL',execute_ddl,3,[{file,"lib/ecto/adapters/mysql.ex"},{line,101}]}]}}
init terminating in do_boot ()

Crash dump is being written to: erl_crash.dump...done

Here’s what I found on mariaex github issue https://github.com/xerions/mariaex/issues/79 which is still open, but the change log https://github.com/xerions/mariaex/blob/master/CHANGELOG.md#078 seems to said it’s implemented.

I could connect to my database server running mysql in command line with the client keys. Not sure what could be wrong here, any suggest? Thanks very much.


Here’s what I got when running release on my local computer:

23:21:13.460 [error] Mariaex.Protocol (#PID<0.1297.0>) failed to connect: ** (Mariaex.Error) failed to upgraded socket: {:options, {:ca
certfile, 'ssl/ca.pem', {:error, :enoent}}}

You could check the server logs if it tells something about a failed handshake, or maybe use wireshark to see what’s going on…

I checked mariadb’s error log and query log, here’s what I got in logs:

4510 Connect   hello@example.org as anonymous on app_prod
4510 Connect   Access denied for user 'hello'@'example.org' (using password: YES)

seems like your username or password is incorrect.

When I remove ssl related config, the migrate will be success. I confirmed it many times, the username and password are correct :).

The error might come from the wrong ssl path. I got some idea from http://www.phoenixframework.org/docs/configuration-for-ssl.

ssl: true,
ssl_opts: [cacertfile: Path.expand("ssl/ca.pem", __DIR__), certfile: Path.expand("ssl/client-cert.pem", __DIR__), keyfile: Path.expand("ssl/client-key.pem", __DIR__)]

And I finally made it connecting to remote database server with ssl enabled on my computer.