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

Specifying vm.args (with hostname) makes "rebar3 shell" crash #27

Open
vasu-dasari opened this issue Apr 18, 2018 · 3 comments
Open

Specifying vm.args (with hostname) makes "rebar3 shell" crash #27

vasu-dasari opened this issue Apr 18, 2018 · 3 comments
Assignees

Comments

@vasu-dasari
Copy link
Contributor

vasu-dasari commented Apr 18, 2018

I have been playing with the example "demo" code from the repo. I wanted to add a sname to the demo Erlang VM. So, created a file called, config/vm.args in the demo directory which looks like:

-sname demo

And issued the following commands from the demo directory:

docker run --rm -v ${HOME}:${HOME} -w `pwd` -it elixir bash # Elixir (1.6) docker environment

And in docker from demo directory:

mix local.rebar --force
mix local.hex --force

rebar3 compile
ERL_FLAGS=" -args_file config/vm.args" rebar3 shell

I see the following error:

root@b40fb051a6c7:demo# ERL_FLAGS=" -args_file config/vm.args" rebar3 shell
===> Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump.

On turning DEBUG=1, I see the following message:

===> sh info:
    cwd: "/Users/vdasari/Developer/demo"
    cmd: elixir -e "IO.puts :code.lib_dir(:elixir)"

===> 	opts: []

===> Port Cmd: elixir -e "IO.puts :code.lib_dir(:elixir)"
Port Opts: [exit_status,{line,16384},use_stdio,stderr_to_stdout,hide,eof]

===> sh(elixir -e "IO.puts :code.lib_dir(:elixir)")
failed with return code 1 and the following output:
Protocol 'inet_tcp': the name demo@b40fb051a6c7 seems to be in use by another Erlang node

===> throw: rebar_abort [{rebar_utils,debug_and_abort,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_utils.erl"},
                                  {line,605}]},
                                {rebar_utils,sh,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_utils.erl"},
                                  {line,197}]},
                                {rebar3_elixir_compile_util,get_details,1,
                                 [{file,
                                   "/Users/vdasari/Developer/demo/_build/default/plugins/rebar3_elixir_compile/src/rebar3_elixir_compile_util.erl"},
                                  {line,66}]},
                                {rebar3_elixir_compile,init,1,
                                 [{file,
                                   "/Users/vdasari/Developer/demo/_build/default/plugins/rebar3_elixir_compile/src/rebar3_elixir_compile.erl"},
                                  {line,8}]},
                                {rebar_state,
                                 '-create_logic_providers/2-fun-0-',2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_state.erl"},
                                  {line,409}]},
                                {lists,foldl,3,
                                 [{file,"lists.erl"},{line,1263}]},
                                {rebar_state,create_logic_providers,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_state.erl"},
                                  {line,408}]},
                                {rebar_plugins,'-handle_plugins/4-fun-0-',4,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_plugins.erl"},
                                  {line,84}]}]
===> Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump.

I generally use this command ERL_FLAGS=" -args_file config/vm.args" rebar3 shell to run rebar3 shell for normal Erlang-Rebar projects. I expected to see this working for Elixir imported projects as well. May I know what do I need to do to make this command work.

@vasu-dasari
Copy link
Contributor Author

Just found that I had to give full path name of where vm.args file is located, that fixed the problem of locating the vm.args file. But, for consistency it will be a good idea to fix this.
Now, I see this error:

===> sh(elixir -e "IO.puts :code.lib_dir(:elixir)")
failed with return code 1 and the following output:
Protocol 'inet_tcp': the name demo@b40fb051a6c7 seems to be in use by another Erlang node

This is a fresh docker instance, and no other instances of demo are running. So, this error message looks suspicious. Can you help me fix this error?

@vasu-dasari vasu-dasari changed the title Specifying ERL_FLAGS makes "rebar3 shell" crash Specifying vm.args (with hostname) makes "rebar3 shell" crash Apr 19, 2018
@vasu-dasari
Copy link
Contributor Author

Ok. I see the reason why it is failing. Will have a PR shortly.
Now I start application with:

ERL_FLAGS=" -args_file ${PWD}config/vm.args" rebar3 shell and my vm.args file contains, -snmae demo.

rebar3 shell tries to issue compile directive to provider(plugins) to see if the source code has to be re-compiled. rebar3 would have set ERL_FLAGS to "ERL_FLAGS= -args_file .../demo/config/vm.args" already before calling this. And also, it would have started the VM already with vm.args. Lets call this parent VM, and will have sname as specified in vm.args.

In rebar3_elixir_compile_util, a dependency elixir file is compiled with following command: /usr/local/bin/mix deps.get.

Now, this would spawn another VM with previously set ERL_FLAGS. And this new VM could not be spawned because the node name is already in use(becuase of parent VM created by rebar3 shell).

So, the fix would be to create wrapper for rebar_utils:sh() in rebar3_elixir_compile_util as:

sh(Command, Options) ->
    rebar_utils:sh(Command, [{env, [{"ERL_FLAGS", ""}]} | Options]).

I will shortly create pull request for this.

vasu-dasari added a commit to vasu-dasari/rebar3_elixir_compile that referenced this issue Apr 20, 2018
Make a wrapper for rebar_utils:sh() so that this plugin can invoke elixir/mix commands with ERL_FLAGS set to "". This is done so that the settings of ERL_FLAGS do not influence these commands.

For more information refer to: Issue 27, barrel-db#27
@benoitc benoitc self-assigned this Jun 27, 2018
@benoitc
Copy link
Member

benoitc commented Jun 27, 2018

him interesting I wonder if except the node name resolution something else can be problematic. Imo we should be able to pass includes -I and path -pa args at least so everything would be included. Thoughts?

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

No branches or pull requests

2 participants