From 672f2f75c979898b254d07c037b2ad637de2ae0e Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 12 Jun 2025 15:46:54 +0200 Subject: [PATCH 1/2] reset worker on report error --- ebin/gmhive_client.app | 2 +- src/gmhc_server.erl | 9 +++++---- zomp.meta | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ebin/gmhive_client.app b/ebin/gmhive_client.app index 8037248..a3b99a8 100644 --- a/ebin/gmhive_client.app +++ b/ebin/gmhive_client.app @@ -1,6 +1,6 @@ {application,gmhive_client, [{description,"Gajumaru Hive Client"}, - {vsn,"0.4.3"}, + {vsn,"0.4.4"}, {registered,[]}, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, gmconfig,gmhive_protocol,gmhive_worker]}, diff --git a/src/gmhc_server.erl b/src/gmhc_server.erl index 68476bd..af16c4e 100644 --- a/src/gmhc_server.erl +++ b/src/gmhc_server.erl @@ -272,13 +272,14 @@ incr_worker_error(#worker{errors = Es, index = I} = W, Ws) -> W1 = reset_worker_(W#worker{errors = Es+1}), lists:keyreplace(I, #worker.index, Ws, W1). -maybe_continue(stopped, _, S) -> - S; +%% maybe_continue(stopped, _, S) -> +%% S; maybe_continue(continue, W, S) -> maybe_restart_worker(W, S); maybe_continue(error, W, S) -> ?LOG_INFO("Won't restart worker ~p due to error", [W#worker.index]), - S. + Ws = reset_worker(W, S#st.workers), + S#st{workers = Ws}. maybe_restart_worker(#worker{index = I} = W, #st{candidate = C} = S) -> case maps:get(nonces, C) of @@ -314,7 +315,7 @@ stop_workers_for_seq(Seq, Workers) -> stop_worker(#worker{pid = Pid} = W) when is_pid(Pid) -> MRef = erlang:monitor(process, Pid), ?LOG_DEBUG("Will stop worker ~p (MRef = ~p)", [Pid, MRef]), - exit(Pid, kill), + exit(Pid, shutdown), receive {'EXIT', Pid, _} -> ok; {'DOWN', MRef, process, Pid, _} -> ok diff --git a/zomp.meta b/zomp.meta index 2dceca0..93a4a7a 100644 --- a/zomp.meta +++ b/zomp.meta @@ -2,9 +2,9 @@ {type,app}. {modules,[]}. {prefix,"gmhc"}. -{author,"Ulf Wiger, QPQ AG"}. {desc,"Gajumaru Hive Client"}. -{package_id,{"uwiger","gmhive_client",{0,4,3}}}. +{author,"Ulf Wiger, QPQ AG"}. +{package_id,{"uwiger","gmhive_client",{0,4,4}}}. {deps,[{"uwiger","gmcuckoo",{1,2,3}}, {"uwiger","gmhive_worker",{0,3,0}}, {"otpr","eblake2",{1,0,1}}, -- 2.30.2 From c61ce6df1ad90a019b0ec3e33fbf61e041229a35 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Mon, 16 Jun 2025 22:29:00 +0200 Subject: [PATCH 2/2] Handle empty nonces (zx vsn 0.4.5) --- ebin/gmhive_client.app | 2 +- src/gmhc_server.erl | 17 ++++++++++------- zomp.meta | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ebin/gmhive_client.app b/ebin/gmhive_client.app index a3b99a8..2ffc191 100644 --- a/ebin/gmhive_client.app +++ b/ebin/gmhive_client.app @@ -1,6 +1,6 @@ {application,gmhive_client, [{description,"Gajumaru Hive Client"}, - {vsn,"0.4.4"}, + {vsn,"0.4.5"}, {registered,[]}, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, gmconfig,gmhive_protocol,gmhive_worker]}, diff --git a/src/gmhc_server.erl b/src/gmhc_server.erl index af16c4e..ce7400d 100644 --- a/src/gmhc_server.erl +++ b/src/gmhc_server.erl @@ -107,13 +107,16 @@ handle_cast({from_pool, #{via := Connector, %% We could check whether we have already received the candidate ... %% For now, stop all workers, restart with new candidate try - % Most of the time we don't want to stop the worker. If we do, though, then - % we need to do it more carefully than this, or memory usage will triple. - % Workers1 = stop_workers(Workers), - {Workers2, Cand1} = assign_nonces(Workers, Cand), - #st{candidate = Cand2} = S1 = maybe_request_nonces(S#st{candidate = Cand1}), - NewWorkers = [spawn_worker(W, Cand2) || W <- Workers2], - {noreply, S1#st{workers = NewWorkers}} + %% Most of the time we don't want to stop the worker. If we do, though, then + %% we need to do it more carefully than this, or memory usage will triple. + %% Workers1 = stop_workers(Workers), + %% + %% Nonces may be [], in which case we need to request new nonces first. + #st{candidate = Cand1} = S1 = maybe_request_nonces(S#st{candidate = Cand}), + {Workers2, Cand2} = assign_nonces(Workers, Cand1), + #st{candidate = Cand3} = S2 = maybe_request_nonces(S1#st{candidate = Cand2}), + NewWorkers = [spawn_worker(W, Cand3) || W <- Workers2], + {noreply, S2#st{workers = NewWorkers}} catch Cat:Err:St -> ?LOG_ERROR("CAUGHT ~p:~p / ~p", [Cat, Err, St]), diff --git a/zomp.meta b/zomp.meta index 93a4a7a..b85d6d4 100644 --- a/zomp.meta +++ b/zomp.meta @@ -2,9 +2,9 @@ {type,app}. {modules,[]}. {prefix,"gmhc"}. -{desc,"Gajumaru Hive Client"}. {author,"Ulf Wiger, QPQ AG"}. -{package_id,{"uwiger","gmhive_client",{0,4,4}}}. +{desc,"Gajumaru Hive Client"}. +{package_id,{"uwiger","gmhive_client",{0,4,5}}}. {deps,[{"uwiger","gmcuckoo",{1,2,3}}, {"uwiger","gmhive_worker",{0,3,0}}, {"otpr","eblake2",{1,0,1}}, -- 2.30.2