iex --remsh halts the remote node at end of input
Elixir and Erlang/OTP versions
Elixir 1.20.1, 1.20.4 and main (b77fe287), on Erlang/OTP 28.5.0.2 and 29.1.1.
Operating system
NixOS (Linux)
Current behavior
iex --remsh halts the remote node when the local shell's input ends. In a terminal without line editing (TERM unset, dumb, or a TERM the host's terminfo lacks, for example xterm-kitty on a stock server), Ctrl+D on an empty line ends the input. The same happens when stdin is a pipe.
$ iex --sname target --cookie c
$ TERM=dumb iex --sname client --cookie c --remsh target@$(hostname -s)
iex(target@host)1> ^D
The target node exits with status 0. printf '1\n' | iex --sname client --cookie c --remsh target@host halts it the same way.
iex.erl passes {on_eof, halt} to IEx.Server for both local and remote shells (lib/elixir/src/iex.erl:78), and IEx.Server runs System.halt(0) on the remote node. With line editing, Ctrl+D only deletes forward, so the bug depends on the terminal. erl -remsh does not halt the remote node in the same setups.
Expected behavior
End of input in a remote shell ends the shell and leaves the remote node running, like erl -remsh. Halting on end of input makes sense for a local iex, where the shell owns the node.
A three-line change does it, passing stop_evaluator (IEx.Server's default) in the --remsh branch:
--- a/lib/elixir/src/iex.erl
+++ b/lib/elixir/src/iex.erl
@@ -53,7 +53,7 @@
case get_remsh(Args) of
nil ->
- start_mfa(Args, {elixir, start_cli, []});
+ start_mfa(Args, {elixir, start_cli, []}, halt);
@@ -67,15 +67,15 @@
- {remote, Remote, start_mfa(Args, {?MODULE, sync_remote, [Parent, Ref]})}
+ {remote, Remote, start_mfa(Args, {?MODULE, sync_remote, [Parent, Ref]}, stop_evaluator)}
end.
@@
-start_mfa(Args, MFA) ->
- Opts = [{dot_iex, get_dot_iex(Args)}, {on_eof, halt}],
+start_mfa(Args, MFA, OnEof) ->
+ Opts = [{dot_iex, get_dot_iex(Args)}, {on_eof, OnEof}],
{?MODULE, start, [Opts, MFA]}.
With it, Ctrl+D and piped input end the client with status 0 and the remote node keeps running. Happy to open a PR.
Yes please PR!!
@josevalim noticed this hits releases too, since bin/my_app remote uses iex --remsh. On 1.20.x something like
echo 'IO.puts(1)' | bin/my_app remote
or bin/my_app remote < /dev/null takes the running node down. Tried it with a 1.20.2 release and the node dies, on main it stays up.
Looks like the v1.20 branch still has {on_eof, halt}, so 1.20.4 should have the same problem. Any chance this gets backported for 1.20.5?