<div dir="ltr"><div>I've distilled the flow that triggers the crash and made a demo.<br><br> <a href="https://github.com/g-andrade/enif_send_crash">https://github.com/g-andrade/enif_send_crash</a><br></div><div><br>It implements a dirty NIF which sends messages to a second process using enif_send() and a message containing a heap-allocated term. <br>It increases the number of iterations exponentially until it crashes.<br></div><div><br></div>This is what happens in my machine very consistently (macOS):<br><br>> ./enif_send_crash<br>> Trying to crash (1 iterations)...<br>> Trying to crash (2 iterations)...<br>> Trying to crash (4 iterations)...<br>> Trying to crash (8 iterations)...<br>> Trying to crash (16 iterations)...<br>> Trying to crash (32 iterations)...<br>> Trying to crash (64 iterations)...<br>> Trying to crash (128 iterations)...<br>> Trying to crash (256 iterations)...<br>> Trying to crash (512 iterations)...<br>> Trying to crash (1024 iterations)...<br><div>> beam/erl_nif.c:445:cache_env() Assertion failed: env->hp_end == (env->proc)->stop</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 August 2018 at 09:38, Guilherme Andrade <span dir="ltr"><<a href="mailto:g@gandrade.net" target="_blank">g@gandrade.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<br><div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On 20 June 2018 at 18:39, Sverker Eriksson <span dir="ltr"><<a href="mailto:sverker.eriksson@ericsson.com" target="_blank">sverker.eriksson@ericsson.com</a><wbr>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I suggest you (and everybody during NIF development) to run on a debug-VM.<br>
It's slower but it catches a lot of faults earlier and produces a nicer core<br>
dump. It will catch enif_* API violations such as building tuples/lists/maps<br>
with terms from different environments.<br></blockquote><div><br></div></span><div>I finally found the time to look into this matter again. </div><div><br></div><div>Using a debug build of the VM (20.3), the crash consistently happens due to a failed assertion in line 445 of erl_nif.c[1].</div><div>Other conditions are the same as before.<br></div><div><br></div><div>Is this enlightening in anyway? I've got a 2.8 GiB core dump I can look into if you tell me that's the right direction to go.<br></div><div><br></div><div><br></div><div>[1]: <a href="https://github.com/erlang/otp/blob/OTP-20.3.8.4/erts/emulator/beam/erl_nif.c#L445" target="_blank">https://github.com/erlang/otp/<wbr>blob/OTP-20.3.8.4/erts/<wbr>emulator/beam/erl_nif.c#L445</a><span class="HOEnZb"><font color="#888888"><br></font></span></div></div><span class="HOEnZb"><font color="#888888"><br>-- <br><div class="m_-6609681788290289888gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div>
</font></span></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div>
</div>