nerves-project / shoehorn

Handle OTP application failures without restarting the Erlang VM
Apache License 2.0
44 stars 11 forks source link

Shoehorn.Handler behaviour not working with Elixir 1.16.3 / OTP 26.2.5 #137

Open alanj853 opened 1 month ago

alanj853 commented 1 month ago

Environment

Current behavior

Shoehorn behaviour does not seem to be getting used at all.

Steps to reproduce

  1. First, comment on the "raise" statement in crash_app/lib/crash_app/application.ex (documentation should probably say to do this, as your example does not work as expected without it)
  2. Follow steps in example README
    cd my_project
    mix deps.get
    mix release
    RELEASE_BOOT_SCRIPT=shoehorn _build/dev/rel/my_project/bin/my_project start_iex
  3. Run Application.stop :my_project

Expected behavior

Application should restart, and we should see Logger.info print messages

Actual Behaviour

Application exits, and does not restart. Also, there are no Logger.info prints at all, even if the prints in my_project/lib/my_project/shoehorn_handler.ex are switched to IO.puts/1, which shows the code is not being called at all I think.

pokyuser@docker:/workdir/shoehorn/example/my_project$ RELEASE_BOOT_SCRIPT=shoehorn _build/dev/rel/my_project/bin/my_project start_iex

10:59:59.207 [info] System initialization application started!
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(my_project@docker)1> Application.stop :my_project

11:00:08.784 [notice] Application my_project exited: :stopped
:ok
iex(my_project@docker)2>
nil
iex(my_project@docker)3>
nil
iex(my_project@docker)4> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)5> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)6> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)7> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)8> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)9> Application.stop :my_project
{:error, {:not_started, :my_project}}
iex(my_project@docker)10>
fhunleth commented 4 weeks ago

@alanj853 I've stopped using this feature of Shoehorn, so I'm not in a good spot to help. If you or others can figuring it out and send a patch, I'll gladly merge and make a release. I think we can also bump the lowest version of OTP supported if it's hard to maintain backwards compatibility.

alanj853 commented 1 week ago

But is this not the main feature of shoehorn, to provide a means to restart applications that crash without having to go outside the VM?

fhunleth commented 1 week ago

It is.

alanj853 commented 1 week ago

With some more trial and error, I found that this is due to some change in Elixir 1.15.0. This all works fine with the 1.14.5. What is happening is the handle_event and handle_call implementations in lib/shoehorn/report_handler.ex are not being called anymore, even though init/1 is.

alanj853 commented 1 week ago

I think I have fixed the issue here: https://github.com/nerves-project/shoehorn/pull/138