gleam-lang / otp

📫 Fault tolerant multicore programs with actors
https://hexdocs.pm/gleam_otp/
Apache License 2.0
443 stars 49 forks source link

Add Supervisor shutdown options #65

Open nerdyworm opened 5 months ago

nerdyworm commented 5 months ago

The original issue that I was facing was that supervisors never actually killed their child processes, thus leading to a memory/process leak when my system was running for about a week.

This pull request implements the two strategies that erlang's supervisor employees, timeout and brutal kill.

The root cause of why actors never exit with erlang:exit(pid, normal) is still unknown.

nerdyworm commented 4 months ago

Update: I discovered that using erlang:exit(Pid, normal) from an external process does not stop the process.

I've updated my PR to use erlang:exit(Pid, shutdown). This successfully stops the actors and everything looks perfect.

I've also discovered if your actor traps exits, then you'll have to match on the following in your actor to shut it down, otherwise, it will timeout -> brutal kill.

 Down(ExitMessage(_supervisor_pid, Abnormal("Shutdown"))) -> {
      actor.Stop(Abnormal("shutdown"))
  }