Running NIF code in driver handlers
Max Lapshin
max.lapshin@REDACTED
Tue Sep 15 16:53:18 CEST 2020
I've got ab interesting bug.
I have a driver (it is more convenient than NIF to handle sockets
because the driver has state).
I tried to call enif_make_maps from port_call callback and got into
following backtrace:
erts_maps_put is calling erts_hashmap_insert
then it goes into macro ERTS_VERIFY_UNUSED_TEMP_ALLOC(p);
then goes to erts_proc_sched_data
and fails on ASSERT(ERTS_SCHEDULER_IS_DIRTY(esdp));
Problem is following: I call env = enif_alloc_env();
but I'm running on a scheduler thread, because it is driver port_call callback.
I do not have any working process, so c_p->scheduler_data is zero,
thus this code assumes that I'm on a dirty scheduler thread.
So it seems that it is illegal to call enif_alloc_env in a driver callback and
maybe even illegal to do it in a NIF callback because we already have env?
Should I create a better test example? Is it a designed behaviour or
something that
can be fixed?
More information about the erlang-questions
mailing list