HtPipe prevents the entire Elixir from terminating abnormaly by NIFs.
mix new abort_nif --sup
cd abort_nif
- edit the following files.
mix.exs
lib/abort_nif/application.ex
lib/abort_nif.ex
Makefile
libnif.c
mix deps.get
iex --name main_node --cookie cookie -S mix
AbortNif
has push/1
and pop/0
functions:
iex(main_node@yourhost.local)1> AbortNif.pop()
:empty
iex(main_node@yourhost.local)2> AbortNif.push(1)
:ok
iex(main_node@yourhost.local)3> AbortNif.push(2)
:ok
iex(main_node@yourhost.local)4> AbortNif.pop()
2
iex(main_node@yourhost.local)5> AbortNif.pop()
1
iex(main_node@yourhost.local)6> AbortNif.pop()
:empty
AbortNif
aborts by abort_soft/0
and restart soon by the supervisor.
The state will be empty by restarting:
iex(main_node@yourhost.local)1> AbortNif.push(1)
:ok
iex(main_node@yourhost.local)2> AbortNif.push(2)
:ok
iex(main_node@yourhost.local)3> AbortNif.abort_soft()
:ok
iex(main_node@yourhost.local)4> AbortNif.pop()
:empty
AbortNif
aborts by abort_hard/0
by NIF and restart soon by the supervisor of HtPipe, with some error message from Logger
.
The state will be empty by restarting
iex(main_node@yourhost.local)1> AbortNif.push(1)
:ok
iex(main_node@yourhost.local)2> AbortNif.push(2)
:ok
iex(main_node@yourhost.local)3> AbortNif.abort_hard()
:ok
iex(main_node@yourhost.local)4>
05:28:26.650 [error] Process #PID<20680.102.0> on node :"[email protected]" raised an exception
** (UndefinedFunctionError) function HtPipe.worker/3 is undefined or private
(ht_pipe 0.1.0-dev) HtPipe.worker(#PID<0.220.0>, 5000, #Function<0.51034852/0 in AbortNif.handle_cast/2>)
05:28:31.759 [error] GenServer AbortNif terminating
** (stop) bad return value: nil
Last message: {:"$gen_cast", :abort_hard}
State: [2, 1]
AbortNif.pop
:empty