Skip to content

MySQL Load: Combine sql and exit signal in one port command#724

Merged
greg-rychlewski merged 4 commits intoelixir-ecto:masterfrom
greg-rychlewski:mysql_load_fix
Apr 2, 2026
Merged

MySQL Load: Combine sql and exit signal in one port command#724
greg-rychlewski merged 4 commits intoelixir-ecto:masterfrom
greg-rychlewski:mysql_load_fix

Conversation

@greg-rychlewski
Copy link
Copy Markdown
Member

@greg-rychlewski greg-rychlewski commented Apr 2, 2026

This should catch the case where we call Port.command the second time after the port has closed. Our previous fix caught the case where we have an issue with the first Port.command call sending data packets after it has been closed

# 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!

@greg-rychlewski greg-rychlewski merged commit ad3243f into elixir-ecto:master Apr 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants