From bb837c3c1cff28407088555c41b7800013efa71e Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Thu, 2 Apr 2026 08:46:04 -0400 Subject: [PATCH 1/4] combine sql and exit signal --- lib/ecto/adapters/myxql.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index 6c706dfe..e81432dc 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -591,10 +591,10 @@ defmodule Ecto.Adapters.MyXQL do # 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) - Port.command(port, contents) # Use this as a signal to close the port since we cannot # send an exit command to mysql in batch mode - Port.command(port, ";SELECT '__ECTO_EOF__';\n") + exit_signal = ";SELECT '__ECTO_EOF__';\n" + Port.command(port, [contents, exit_signal]) result = collect_output(port, "") Process.flag(:trap_exit, old_trap_exit) result From 2bdd35abf8ef10d63e102cfc76d49f11c6123055 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Thu, 2 Apr 2026 09:48:57 -0400 Subject: [PATCH 2/4] change to message passing --- lib/ecto/adapters/myxql.ex | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index e81432dc..5250287b 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -588,13 +588,9 @@ 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) - # Use this as a signal to close the port since we cannot - # send an exit command to mysql in batch mode - exit_signal = ";SELECT '__ECTO_EOF__';\n" - Port.command(port, [contents, exit_signal]) + port ! {self(), {:command, contents}} + port ! {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}} result = collect_output(port, "") Process.flag(:trap_exit, old_trap_exit) result @@ -657,9 +653,6 @@ defmodule Ecto.Adapters.MyXQL do collect_output(port, acc) end - {:EXIT, ^port, _reason} -> - {acc, 1} - {^port, {:exit_status, status}} -> {acc, status} end From 7c0ffcf8dd809e8e09886de5149553b44dcf8786 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Thu, 2 Apr 2026 09:54:40 -0400 Subject: [PATCH 3/4] fixes --- lib/ecto/adapters/myxql.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index 5250287b..c53b1780 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -589,11 +589,11 @@ defmodule Ecto.Adapters.MyXQL do ] port = Port.open({:spawn_executable, abs_cmd}, port_opts) + port ! {self(), {:command, contents}} port ! {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}} - result = collect_output(port, "") - Process.flag(:trap_exit, old_trap_exit) - result + + collect_output(port, "") end defp args_env(opts, opt_args) do From 4c4012d739710c4ebb065aa2d5082025d3b7d933 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Thu, 2 Apr 2026 09:58:13 -0400 Subject: [PATCH 4/4] fixes --- lib/ecto/adapters/myxql.ex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index c53b1780..7f175bed 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -589,10 +589,8 @@ defmodule Ecto.Adapters.MyXQL do ] port = Port.open({:spawn_executable, abs_cmd}, port_opts) - - port ! {self(), {:command, contents}} - port ! {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}} - + send(port, {self(), {:command, contents}}) + send(port, {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}}) collect_output(port, "") end