Skip to content

Stop Elixir's CLI consuming app arguments and halting the VM - #230

Open
joshrotenberg wants to merge 1 commit into
burrito-elixir:mainfrom
joshrotenberg:fix/dont-let-elixir-cli-consume-app-args
Open

Stop Elixir's CLI consuming app arguments and halting the VM#230
joshrotenberg wants to merge 1 commit into
burrito-elixir:mainfrom
joshrotenberg:fix/dont-let-elixir-cli-consume-app-args

Conversation

@joshrotenberg

Copy link
Copy Markdown

Fixes #229.

1.6.0 split "-s elixir start_cli" from a single argv element into three. erl does not split argv elements, so the flag was never recognised before and start_cli never ran. Now it does, and it does what it is supposed to: claims --version and --help, treats the first remaining plain argument as a script path, and halts the VM when it finishes.

Two consequences for wrapped applications:

$ probe hello world
No file named hello

$ probe --version
Erlang/OTP 29 [erts-17.0.3] ...
Elixir 1.20.2 (compiled with Erlang/OTP 29)

and, with no arguments at all, an application that never halts exits about 1.3s after boot, which breaks servers and Phoenix applications.

Change

Emit --no-halt and -- after -extra, and strip them back off in Burrito.Util.Args.

--no-halt restores the pre-1.6.0 lifetime, -- stops the CLI claiming arguments, and start_cli still runs, so whatever the split in #225 was made for is unaffected.

Reverting to the single joined element would also fix both, but only by making start_cli silently not run again.

Verification

A 12-line application whose only dependency is burrito, built on macOS 26 arm64 with Zig 0.16.0, and on Linux arm64 in a container.

Arguments, before and after:

                        1.6.0                      patched
probe hello world       No file named hello        argv=["hello", "world"]
probe --version         Elixir 1.20.2 ...          argv=["--version"]
probe --help            Standalone options ...     argv=["--help"]
probe --transport stdio No file named --transport  argv=["--transport", "stdio"]

Lifetime, no arguments, application never halts:

result
1.6.0 exits after 1289ms, rc=0
patched still running at 12s, killed by timeout

Not broken by the change:

  • exit codes propagate (System.halt(7) gives 7)
  • maintenance directory and maintenance meta work
  • the EPIPE handling from feat: Zig 0.16.0 compatibility #225 still terminates cleanly when piped into head -3, on both platforms
  • an application passing its own -- still receives it, since only the exact leading --no-halt -- pair is stripped

Also exercised against a real application: an MCP server that takes --transport and --port and then runs indefinitely. On 1.6.0 it cannot start; with this change it parses its flags, completes a protocol handshake over stdio, serves a live tool call, and exits 0 when its client disconnects.

One note for the docs: System.argv/0 is populated only once start_cli runs, which is after Application.start/2, so applications still need Burrito.Util.Args.

1.6.0 split "-s elixir start_cli" from a single argv element into three. erl
does not split argv elements, so the flag was never recognised before and
start_cli never ran. Now it does, and it does what it is supposed to: claims
--version and --help, treats the first remaining plain argument as a script
path, and halts the VM when it finishes.

Two consequences for wrapped applications:

    $ probe hello world
    No file named hello

    $ probe --version
    Elixir 1.20.2 (compiled with Erlang/OTP 29)

and, with no arguments at all, an application that never halts exits ~1.3s
after boot, which breaks servers and Phoenix applications.

Emit --no-halt and -- after -extra, and strip them back off in
Burrito.Util.Args. --no-halt restores the pre-1.6.0 lifetime, -- stops the CLI
claiming arguments, and start_cli still runs, so the boot behaviour the split
was made for is unaffected.

Fixes burrito-elixir#229
@gilbertwong96

Copy link
Copy Markdown
Contributor

@doawoo This PR looks good to me. Could you please merge it and bump a new version ?

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.

1.6.0: Elixir's CLI consumes application arguments and halts the VM

2 participants