Skip to content

Commit 14b47b0

Browse files
fix mysql structure load failures (#727)
1 parent ad3243f commit 14b47b0

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/ecto/adapters/myxql.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,13 @@ defmodule Ecto.Adapters.MyXQL do
588588
args: args
589589
]
590590

591+
# Trap exits in case mysql dies in the middle of execution so that we can surface the error
592+
old_trap_exit = Process.flag(:trap_exit, true)
591593
port = Port.open({:spawn_executable, abs_cmd}, port_opts)
592-
send(port, {self(), {:command, contents}})
593-
send(port, {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}})
594-
collect_output(port, "")
594+
Port.command(port, [contents, ";SELECT '__ECTO_EOF__';\n"])
595+
result = collect_output(port, "")
596+
Process.flag(:trap_exit, old_trap_exit)
597+
result
595598
end
596599

597600
defp args_env(opts, opt_args) do
@@ -651,6 +654,9 @@ defmodule Ecto.Adapters.MyXQL do
651654
collect_output(port, acc)
652655
end
653656

657+
{:EXIT, ^port, _reason} ->
658+
{acc, 1}
659+
654660
{^port, {:exit_status, status}} ->
655661
{acc, status}
656662
end

0 commit comments

Comments
 (0)