rusterlium / rustler

Safe Rust bridge for creating Erlang NIF functions
https://docs.rs/crate/rustler
Apache License 2.0
4.3k stars 224 forks source link

[Release Candidate] on_load error when checking out different branches #324

Closed hazardfn closed 4 years ago

hazardfn commented 4 years ago

Sometimes when switching between branches, running mix deps.get and then compiling this error pops up:

14:14:56.816 [warn]  The on_load function for module asn1rt_nif returned:
{:badarg, [{:erlang, :load_nif, [:erlang, :apply], []}, {:asn1rt_nif, :load_nif, 0, [file: 'asn1rt_nif.erl', line: 58]}, {:code_server, :"-handle_on_load/5-fun-0-", 1, [file: 'code_server.erl', ...]}]}
14:14:56.835 [error] Process #PID<0.3742.0> raised an exception
** (ArgumentError) argument error
    :erlang.load_nif(:erlang, :apply)
    (asn1 5.0.13) asn1rt_nif.erl:58: :asn1rt_nif.load_nif/0
    (kernel 7.0) code_server.erl:1355: anonymous fn/1 in :code_server.handle_on_load/5

It doesn't seem to cause any immediate/noticeable issues and started happening for me when using OTP 23.0. The thing that stands out to me is the arguments to load_nif/2 look completely wrong (:erlang, :apply)

The error comes from the use Rustler macro line hence why I am reporting it here, some changes to NIFs were bought into 23.0 but nothing that was supposed to break compatibility as far as I know. One thing that could be related is: https://github.com/erlang/otp/commit/a4e8656d1aa4bde0bbfab6a52585add5d7951bd1

evnu commented 4 years ago

I managed to reproduce this on 387fd8a (rustler-0.22.0-rc.0) as well as on the current master 427da64. Running mix test in rustler_tests:

~/tools/rustler/rustler_tests(387fd8a ✗) mix test
Compiling NIF crate :binary_example (native/binary_example)...
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Compiling NIF crate :rustler_test (native/rustler_test)...
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Compiling NIF crate :deprecated_macros (native/deprecated_macros)...
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s

21:01:37.982 [error] Process #PID<0.242.0> raised an exception
** (ArgumentError) argument error
    :erlang.load_nif(:erlang, :apply)
    (rustler_test 0.0.1) lib/rustler_test.ex:6: RustlerTest.__init__/0
    (kernel 7.0) code_server.erl:1355: anonymous fn/1 in :code_server.handle_on_load/5

21:01:38.009 [warn]  The on_load function for module Elixir.RustlerTest returned:
{:badarg, [{:erlang, :load_nif, [:erlang, :apply], []}, {RustlerTest, :__init__, 0, [file: 'lib/rustler_test.ex', line: 6]}, {:code_server, :"-handle_on_load/5-fun-0-", 1, [file: 'code_server.erl', ...]}]}

21:01:37.993 [warn]  The on_load function for module Elixir.RustlerTest returned:
{:error, {:reload, 'NIF library already loaded (reload disallowed since OTP 20).'}}

This doesn't happen every time, but it happens often enough. When the above happens, the tests hang here.

EDIT: This is not the same message as in the description of this issue (it doesn't error out in asn1rt here), but I think the cause is related. asn1rt is a module within OTP.

evnu commented 4 years ago

This OTP issue here seems related.

evnu commented 4 years ago

https://github.com/erlang/otp/pull/2649 this might fix the problem.

hazardfn commented 4 years ago

@evnu I'll install erlang maint and get back to you, though I suspect given your speed getting back on these things, you're already on it 😆

evnu commented 4 years ago

I built OTP maint with kerl and cannot reproduce the issue anymore with mix test.

I also ran mix test in a loop for some time (+ stress -c8), no hang-ups happened anymore. I will close the issue here. @hazardfn thanks for the report! Feel free to reopen if you encounter the problem again.

kerl ``` ~/tools/otp(master ✗) kerl build git https://github.com/erlang/otp.git maint maint Checking out Erlang/OTP git repository from https://github.com/erlang/otp.git... Building Erlang/OTP maint from git, please wait... APPLICATIONS DISABLED (See: /home/evnu/.kerl/builds/maint/otp_build_git.log) * jinterface : No Java compiler found * odbc : ODBC library - link check failed DOCUMENTATION INFORMATION (See: /home/evnu/.kerl/builds/maint/otp_build_git.log) * documentation : * fop is missing. * Using fakefop to generate placeholder PDF files. Erlang/OTP maint from git has been successfully built ~/tools/otp(master ✗) kerl install usage: /usr/bin/kerl install [directory] [1] 97406 exit 1 kerl install ~/tools/otp(master ✗) kerl install maint ~/kerl/maint Installing Erlang/OTP git (maint) in /home/evnu/kerl/maint... You can activate this installation running the following command: . /home/evnu/kerl/maint/activate Later on, you can leave the installation typing: kerl_deactivate ~/tools/otp(master ✗) . /home/evnu/kerl/maint/activate ```
evnu commented 4 years ago

This should be fixed as of OTP 23.0.3