Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
fix: Session crash stop (#350)
Browse files Browse the repository at this point in the history
* fix: Session crash stop

* fix credo

* add logger

* fix test

---------

Co-authored-by: Thomas DA ROCHA <thomas.darocha@lenra.io>
  • Loading branch information
jonas-martinez and taorepoara authored Aug 31, 2023
1 parent d657ea5 commit e8ab33c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/environment/dynamic_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,26 @@ defmodule ApplicationRunner.Environment.DynamicSupervisor do
def session_stopped(env_id) do
session_pid = Swarm.whereis_name(Session.DynamicSupervisor.get_name(env_id))

session_pid
|> Process.alive?()
|> if do
if is_pid(session_pid) do
session_pid
|> DynamicSupervisor.count_children()
|> case do
%{supervisors: 0} -> stop_env(env_id)
_any -> :ok
|> Process.alive?()
|> if do
session_pid
|> DynamicSupervisor.count_children()
|> case do
%{supervisors: 0} -> stop_env(env_id)
_any -> :ok
end
else
Logger.critical(
"Session.DynamicSupervisor for environment #{env_id} is not running. This should not occur, environment stopped"
)

stop_env(env_id)
end
else
Logger.critical(
"Session.DynamicSupervisor for environment #{env_id} is not running. This should not occur, environment stopped"
Logger.warning(
"Session.DynamicSupervisor pid for environment #{env_id} has not been found. Maybe the session has crashed. Environment stopped"
)

stop_env(env_id)
Expand Down

0 comments on commit e8ab33c

Please sign in to comment.