Adjust stop reasons for server processes (#958)

* Adjust stop reasons for server processes

* Update lib/livebook/unique_task.ex

Co-authored-by: José Valim <jose.valim@dashbit.co>

Co-authored-by: José Valim <jose.valim@dashbit.co>
This commit is contained in:
Jonatan Kłosko 2022-01-30 13:30:33 +01:00 committed by GitHub
parent d2344a5c3b
commit 51db7b482b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 11 deletions

View file

@ -57,13 +57,13 @@ defmodule WxDemo.Window do
@impl true
def handle_event({:wx, @wx_id_exit, _, _, _}, state) do
:init.stop()
{:stop, :normal, state}
{:stop, :shutdown, state}
end
@impl true
def handle_event({:wx, _, _, _, {:wxClose, :close_window}}, state) do
:init.stop()
{:stop, :normal, state}
{:stop, :shutdown, state}
end
@impl true

View file

@ -38,9 +38,9 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
* `:auto_termination` - whether to terminate the manager
when the last runtime server terminates. Defaults to `true`.
* `:parent_node` - indicates which node spawned the node manager.
It is used to disconnect the node when the server terminates,
which happens when the last session using the node disconnects.
* `:parent_node` - indicates which node spawned the node manager.
It is used to disconnect the node when the server terminates,
which happens when the last session using the node disconnects.
Defaults to `nil`
"""
def start(opts \\ []) do
@ -140,8 +140,11 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
def handle_info({:DOWN, _, :process, pid, _}, state) do
if pid in state.runtime_servers do
case update_in(state.runtime_servers, &List.delete(&1, pid)) do
%{runtime_servers: [], auto_termination: true} = state -> {:stop, :normal, state}
state -> {:noreply, state}
%{runtime_servers: [], auto_termination: true} = state ->
{:stop, :shutdown, state}
state ->
{:noreply, state}
end
else
{:noreply, state}

View file

@ -161,7 +161,7 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
end
def handle_info({:DOWN, _, :process, owner, _}, %{owner: owner} = state) do
{:stop, :normal, state}
{:stop, :shutdown, state}
end
def handle_info({:DOWN, _, :process, pid, reason}, state) do

View file

@ -17,7 +17,7 @@ defmodule Livebook.UniqueTask.Task do
@impl true
def handle_continue(fun, state) do
fun.()
{:stop, :normal, state}
{:stop, :shutdown, state}
end
end
@ -75,6 +75,8 @@ defmodule Livebook.UniqueTask do
{:DOWN, ^ref, :process, ^pid, reason} ->
case reason do
:normal -> :ok
:shutdown -> :ok
{:shutdown, _} -> :ok
:noproc -> :ok
_ -> :error
end

View file

@ -45,13 +45,13 @@ if Mix.target() == :app do
@impl true
def handle_event({:wx, @wx_id_exit, _, _, _}, state) do
:init.stop()
{:stop, :normal, state}
{:stop, :shutdown, state}
end
@impl true
def handle_event({:wx, _, _, _, {:wxClose, :close_window}}, state) do
:init.stop()
{:stop, :normal, state}
{:stop, :shutdown, state}
end
# TODO: investigate "Universal Links" [1], that is, instead of livebook://foo, we have