"be careful with the instructions you are executing [rpc]" Why?

The Mix Release documentation states the following with regards to rpc commands:

Another way to run commands is with rpc , which will connect to the system currently running and instruct it to execute the given expression. This means you need to guarantee the system was already started and be careful with the instructions you are executing. You can also use remote to connect a remote IEx session to the system.

This raised a question for me: what are the dangers hinted at here of runing rpc?

Is it that one could impact normal running application processes whereas eval would run things in a more contained way? Any additional explanation and/or examples would be super helpful.

Thank you!

2 Likes

Hello, me, four years ago.

rpc “EXPR” Executes the given expression remotely on the running system
mix release — Mix v1.17.1

:rpc is an integrated Remote Procedure Call system in Erlang itself. You need a running node to execute the RPC command on is all this is saying. And since you can execute any old Elixir with this command, it’s a sharp knife that should be used with care. Make sure you understand the implications of running this code on that node.

Here is where :rpc is called and handled in the Mix CLI code. If the node isn’t available it’ll fail and return an error saying as much.

It still blows me away that we can do stuff like this, so cool!

5 Likes