Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to eval using -s init stop in OTP 26 #6916

Closed
starbelly opened this issue Feb 24, 2023 · 5 comments
Closed

Unable to eval using -s init stop in OTP 26 #6916

starbelly opened this issue Feb 24, 2023 · 5 comments
Assignees
Labels
bug Issue is reported as a bug

Comments

@starbelly
Copy link
Contributor

Describe the bug
Up until erlang otp 26 using -s init stop with an -eval switch would allow one to grab some info about erts, this was useful in that one could use this method such in Makefiles, shell scripts, etc.

This now fails with a failed to eval error message. There is a work around for this, which is simply to call init:stop/0 as part of the eval. This in fact may not be a bug and is intentional, but I didn't see it listed anywhere in release notes.

To Reproduce

$ erl -noshell -eval "io:format(\"~s\/erts-~s/include/\", [code:root_dir(), erlang:system_info(version)])."
Error! Failed to eval: io:format("~s/erts-~s/include", [code:root_dir(), erlang:system_info(version)]).

Expected behavior

$ erl -noshell -s init stop -eval "io:format(\"~s\/erts-~s/include/\", [code:root_dir(), erlang:system_info(version)])."
/path/to/erlang/26.0-rc1/erts-14.0/include/

Note that the output will of course differ from platform to platform and depending how exactly you installed erlang/otp.

Work around :

$ erl -noshell -eval "io:format(\"~s\/erts-~s/include/\", [code:root_dir(), erlang:system_info(version)]), init:stop()."
/path/to/erlang/26.0-rc1/erts-14.0/include/

Affected versions
The OTP versions that are affected by this bug.

OTP-26.0-rc1

Additional context
No additional context.

@starbelly starbelly added the bug Issue is reported as a bug label Feb 24, 2023
@josevalim
Copy link
Contributor

josevalim commented Feb 24, 2023

Keep in mind the original code is faulty. init:stop is a non-blocking operation to shut down the system, so your previous code had a race condition in that the second -s may or may not be executed at all. Try this out:

$ erl -noshell -s init stop -eval "receive after 0 -> ok end, erlang:display(oops)."
oops

But if you increase the timeout:

$ erl -noshell -s init stop -eval "receive after 1000 -> ok end, erlang:display(oops)."

So you should move the -s init stop to the end. But I would recommend using -s erlang halt for quicker shutdowns anyway.

@josevalim
Copy link
Contributor

I have debugged the root cause of the error:

{error,terminated,[{io,format,["~s/erts-~s/include/",["/Users/jose/OSS/otp","13.1.4"]],[{file,"io.erl"},{line,94},{error_info,#{cause=>{io,terminated},module=>erl_stdlib_errors}}]},{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,744}]},{init,start_it,2,[]},{init,start_em,2,[]},{init,do_boot,3,[]}]}

The io device has since them been terminate (due to init:stop/0).

@starbelly
Copy link
Contributor Author

Per @josevalim I'm going to close this. Thanks!

@starbelly starbelly reopened this Feb 27, 2023
@starbelly
Copy link
Contributor Author

Re-opened this per other reports of this issue and someone on Erlang/OTP team saying this is indeed a bug.

@frazze-jobb frazze-jobb self-assigned this Feb 27, 2023
@frazze-jobb
Copy link
Contributor

According to documentation:

-eval Expr
Scans, parses, and evaluates an arbitrary expression Expr during system initialization. If any of these steps fail (syntax error, parse error, or exception during evaluation), Erlang stops with an error message. In the following example Erlang is used as a hexadecimal calculator:

% erl -noshell -eval 'R = 16#1F+16#A0, io:format("~.16B~n", [R])' -s erlang halt
BF

If multiple -eval expressions are specified, they are evaluated sequentially in the order specified. -eval expressions are evaluated sequentially with -s and -run function calls (this also in the order specified). As with -s and -run, an evaluation that does not terminate blocks the system initialization process.

starbelly added a commit to starbelly/procket that referenced this issue May 18, 2023
In Erlang/OTP 26 a race condition was uncovered when using `-eval` with `-s init stop` (i.e., it was always there, but most of the community lucked out in not running into it). 

See erlang/otp#6916 for details
msantos added a commit to msantos/epcap that referenced this issue May 19, 2023
msantos added a commit to msantos/crypt that referenced this issue May 20, 2023
msantos added a commit to msantos/inert that referenced this issue May 21, 2023
msantos added a commit to msantos/alcove that referenced this issue May 22, 2023
msantos added a commit to msantos/prx that referenced this issue May 23, 2023
msantos added a commit to msantos/stdio that referenced this issue May 24, 2023
msantos added a commit to msantos/srly that referenced this issue May 25, 2023
msantos added a commit to msantos/ewpcap that referenced this issue May 26, 2023
Also resolves issues with erlang/otp#6916 for
erlang 26.
msantos added a commit to msantos/cerck that referenced this issue May 27, 2023
msantos added a commit to msantos/perc that referenced this issue May 28, 2023
msantos added a commit to msantos/epcap_compile that referenced this issue May 29, 2023
msantos added a commit to msantos/cm17a that referenced this issue May 30, 2023
* doc: use ex_doc
* dep: update srly

Ref: erlang/otp#6916
msantos added a commit to msantos/stk500 that referenced this issue May 31, 2023
* doc: use ex_doc
* dep: update srly

Ref: erlang/otp#6916
msantos added a commit to msantos/gen_icmp that referenced this issue Jun 1, 2023
msantos added a commit to msantos/gen_icmp that referenced this issue Jun 2, 2023
Update deps for erlang 26 (erlang/otp#6916).
msantos added a commit to msantos/tunctl that referenced this issue Jun 16, 2023
petermm added a commit to petermm/tflite_beam that referenced this issue Jul 19, 2023
cocoa-xu added a commit to cocoa-xu/tflite_beam that referenced this issue Jul 19, 2023
* add otp26 to precompile workflows

* fix  -s init stop

see erlang/otp#6916

* using -s erlang halt for quicker shutdowns

---------

Co-authored-by: Cocoa <[email protected]>
Zanfa added a commit to Zanfa/rebar3_run that referenced this issue Aug 2, 2023
Before OTP 26 `-s init stop` seemed to suffice, but it no longer seems to work for evaluating include/lib dirs. Using `-s erlang halt` is recommended per erlang/otp#6916 (comment)
feng19 added a commit to feng19/erlang-usb that referenced this issue Apr 18, 2024
In Erlang/OTP 26 a race condition was uncovered when using `-eval` with `-s init stop` (i.e., it was always there, but most of the community lucked out in not running into it).

See erlang/otp#6916 for details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug
Projects
None yet
Development

No branches or pull requests

3 participants