Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to use messages to talk to the port, instead of using command. The message is asynchronous and always succeed:

port ! {self(), {:command, contents}}
port ! {self(), {:command, ";SELECT '__ECTO_EOF__';\n"}}

We will know if it fails when we collect the output below. This way there is no chance we fail prematurely on Port.command. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

btw I'm not sure if this is expected or not, but when I used port ! ... instead of send(port, ...) I got an error complaining port/1 is not a function. just thought I would let you know in case it's an issue you are not expecting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the Erlang syntax cause I was writing some Erlang earlier today 😅 It is all good!

result = collect_output(port, "")
Process.flag(:trap_exit, old_trap_exit)
result
Expand Down
Loading