Gopher: Fix crash on (re)boot when ConfigDB is enabled
Ranch listener wasn't being properly stopped when the Gopher GenServer
received a shutdown message due Restarter rebooting Pleroma to apply
ConfigDB configuration (originating from
Config.TransferTask.load_and_update_env/2) when ConfigDB is enabled.
Handle by trapping exits in the GenServer, which causes the terminate/2
function to be called and the Ranch listener to be stopped from there.
23:22:29.871 [error] GenServer Restarter.Pleroma terminating
** (MatchError) no match of right hand side value:
{:error,
{{:shutdown,
{:failed_to_start_child, Pleroma.Gopher.Server,
{{:badmatch, {:error, {:already_started, #PID<0.4801.0>}}},
[
{Pleroma.Gopher.Server, :init, 1,
[file: ~c"lib/pleroma/gopher/server.ex", line: 25]},
{:gen_server, :init_it, 2, [file: ~c"gen_server.erl", line: 2276]},
{:gen_server, :init_it, 6, [file: ~c"gen_server.erl", line: 2236]},
{:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 333]}
]}}}, {Pleroma.Application, :start, [:normal, []]}}}
(restarter 0.1.0) lib/pleroma.ex:104: Restarter.Pleroma.do_restart/1
(restarter 0.1.0) lib/pleroma.ex:96: Restarter.Pleroma.handle_cast/2
(stdlib 7.2) gen_server.erl:2460: :gen_server.try_handle_cast/3
(stdlib 7.2) gen_server.erl:2418: :gen_server.handle_msg/3
(stdlib 7.2) proc_lib.erl:333: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:after_boot, :dev}}
State: %{rebooted: false, need_reboot: false, after_boot: false}
This commit is contained in:
parent
1c685ea41a
commit
eed4f4bba8
2 changed files with 10 additions and 2 deletions
1
changelog.d/gopher-genserver-crash-on-boot.fix
Normal file
1
changelog.d/gopher-genserver-crash-on-boot.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Gopher: Fix Ranch listener not being stopped properly on Pleroma restart when database configuration is enabled
|
||||||
|
|
@ -21,10 +21,13 @@ defmodule Pleroma.Gopher.Server do
|
||||||
|
|
||||||
def init([ip, port]) do
|
def init([ip, port]) do
|
||||||
Logger.info("Starting gopher server on #{port}")
|
Logger.info("Starting gopher server on #{port}")
|
||||||
|
Process.flag(:trap_exit, true)
|
||||||
|
|
||||||
|
listener = :gopher
|
||||||
|
|
||||||
{:ok, _pid} =
|
{:ok, _pid} =
|
||||||
:ranch.start_listener(
|
:ranch.start_listener(
|
||||||
:gopher,
|
listener,
|
||||||
:ranch_tcp,
|
:ranch_tcp,
|
||||||
%{
|
%{
|
||||||
num_acceptors: 100,
|
num_acceptors: 100,
|
||||||
|
|
@ -35,7 +38,11 @@ defmodule Pleroma.Gopher.Server do
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
{:ok, %{ip: ip, port: port}}
|
{:ok, %{ip: ip, port: port, listener: listener}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def terminate(_reason, state) do
|
||||||
|
:ranch.stop_listener(state.listener)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue