From 4700b05bb32537307bf7c7142a616cd31ab65c7d Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Tue, 7 Apr 2026 08:45:39 -0400 Subject: [PATCH] fix mysql structure load failures --- lib/ecto/adapters/myxql.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index 7f175bed..6026cb26 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -588,10 +588,13 @@ defmodule Ecto.Adapters.MyXQL do args: args ] + # Trap exits in case mysql dies in the middle of execution so that we can surface the error + old_trap_exit = Process.flag(:trap_exit, true) port = Port.open({:spawn_executable, abs_cmd}, port_opts) - send(port, {self(), {:command, contents}}) - send(port, {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}}) - collect_output(port, "") + Port.command(port, [contents, ";SELECT '__ECTO_EOF__';\n"]) + result = collect_output(port, "") + Process.flag(:trap_exit, old_trap_exit) + result end defp args_env(opts, opt_args) do @@ -651,6 +654,9 @@ defmodule Ecto.Adapters.MyXQL do collect_output(port, acc) end + {:EXIT, ^port, _reason} -> + {acc, 1} + {^port, {:exit_status, status}} -> {acc, status} end