Debug Emulator fails to run with exqlite NIF

OTP Version: 24.1.3
Elixir Version: 1.12.1
Machine: Linux GNU x86_64

Hi,

I am looking for help with the following error I am getting when I try to run my elixir project with the debug emulator. Here is the error:

Erlang/OTP 24 [erts-12.1.3] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit] [type-assertions] [debug-compiled] [lock-checking]
Interactive Elixir (1.12.1) - press Ctrl+C to exit (type h() ENTER for help)
beam/erl_nif.c:2444:enif_open_resource_type() Assertion failed: module_str == ((void *)0)
                                                                                         Aborted (core dumped)

When I used the regular emulator, beam.smp, the project runs fine. The issue is possibly coming from the exqlite NIF that is compiled, or maybe the VM itself. I am not sure.

Just some background, I am working on an app that uses an SQLite DB, and it is currently seg faulting (not related to this issue). So I am trying to get a core dump using the debug version of the erlang VM, as per the erlang documentation. But when I try to run the app with the debug emulator, it fails with the above error.

My erlang version of 24.1.3 has been compiled manually, and was configured with the following options:

./configure \
 --prefix=$OTP_24_INSTALL \
 --without-javac \
 --disable-smp-support \
 --disable-hipe \
 --without-dynamic-trace \
 --without-odbc \
 --without-observer

I then compile Elixir with this version erlang.

For switching between the debug and regular versions of the erlang VM, I simply rename the beam.debug.smp file to beam.smp in the erlang install dir, as I do not know of another way to run elixir with the debug erlang VM (I would be very grateful if someone could tell me the correct way).

Any help with the above error would be greatly appreciated, as I do not understand why it works with the regular beam.smp file, but not with beam.debug.smp file.

To help show the issue, I have created a demo repo here: GitHub - alanj853/debug_project.

To setup

bash setup.sh

To show problem with debug emulator

bash enable_debug.sh
bash run_app.sh

To show working with regular emulator

bash enable_regular.sh
bash run_app.sh

Thank you.

  • The debug BEAM can (and should) be started through the -emu_type debug (see, e.g. Debugging NIFs and Port Drivers — Erlang System Documentation v27.2)
  • You can pass arguments to erl from Elixir via the --erl parameter
  • Even simpler (because you don’t have to hunt down the correct passthrough argument) is using the ERL_AFLAGS environment variable:
    $ ERL_AFLAGS="-emu_type debug" bash run_app.sh
    

On the actual error: This really sounds like a memory corruption/“confusion”. The respective parameter (module_name) is a static constant in the library (exqlite/c_src/sqlite3_nif.c at main · elixir-sqlite/exqlite · GitHub and once more below).

1 Like

By the way, if you’re looking for sqlite3 Erlang bindings that don’t core dump, - as a shameless plug, I have one here: GitHub - max-au/sqlite: sqlite3 NIF bindings for Erlang

2 Likes

Indeed. And you know what? Apparently working on resource types for Rustler only 6 months ago was enough to forget that the module_str actually has to be NULL (I always get confused by the way assertion errors look like), which you pass correctly in your version. I’ll push a PR for exqlite to fix this.

/edit: The module_str parameter of open_resource_type has to be NULL by filmor · Pull Request #312 · elixir-sqlite/exqlite · GitHub

/edit: Even better, it’s also wrong in Rustler, fix coming up :slight_smile:

/edit: Strike that, in Rustler I am using the newer enif_init_resource_type or enif_open_resource_type_x, which have dropped the always-NULL parameter.

1 Like

Shots across the bow. :wink:

Jokes aside, if you see an issue where a core dump happens, submit an issue. I’m pretty quick at resolving things.