Skip to content

Commit a3b2db3

Browse files
committed
Tau - move keepalive out of the tau_server supervision tree
It's now more top level (is it ok doing this?) so it doesn't get restarted - this process should only be started once and left alone.
1 parent 55aee00 commit a3b2db3

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

app/server/beam/tau/lib/tau.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use Application
2626

2727
# Although we don't use the supervisor name below directly,
2828
# it can be useful when debugging or introspecting the system.
29+
:tau_keepalive.start_link(daemon_port)
2930
:tau_server_sup.start_link()
3031
end
3132

app/server/beam/tau/src/tau_server/tau_keepalive.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414

1515
-module(tau_keepalive).
1616

17-
-export([start/1, init/1, loop/1]).
17+
-export([start_link/1, init/1, loop/1]).
1818

19-
start(DaemonPortNum) ->
20-
spawn(?MODULE, init, [DaemonPortNum]).
19+
start_link(DaemonPortNum) ->
20+
spawn_link(?MODULE, init, [DaemonPortNum]).
2121

2222
init(DaemonPortNum) ->
2323
logger:info("connecting to Daemon via TCP...", []),
2424
{ok, DaemonSocket} = gen_tcp:connect({127,0,0,1}, DaemonPortNum, [
2525
binary,
2626
{active, true},
2727
{packet, 4},
28-
{keepalive, true}
28+
{keepalive, false}
2929
]),
3030
OSPid = os:getpid(),
3131
PidMsg = osc:encode(["/tau_pid", OSPid]),
3232
logger:info("Sending Pid ~p to Daemon...", [OSPid]),
3333
gen_tcp:send(DaemonSocket, PidMsg),
34-
KillSwitch = erlang:start_timer(5000, self(), trigger_kill_switch),
34+
KillSwitch = erlang:send_after(5000, self(), trigger_kill_switch),
3535
logger:info("Waiting for keepalive messages..."),
3636
loop(KillSwitch).
3737

@@ -41,8 +41,8 @@ loop(KillSwitch) ->
4141
try osc:decode(Bin) of
4242
{cmd, ["/system/keepalive"]} ->
4343
logger:debug("Received keepalive message from Daemon", []),
44-
erlang:cancel_timer(KillSwitch),
45-
NewKillSwitch = erlang:start_timer(5000, self(), trigger_kill_switch),
44+
ok = erlang:cancel_timer(KillSwitch, [{async, true}, {info, false}]),
45+
NewKillSwitch = erlang:send_after(5000, self(), trigger_kill_switch),
4646
?MODULE:loop(NewKillSwitch);
4747
Other ->
4848
logger:error("Unexpected message from Daemon:~p", [Other]),
@@ -53,7 +53,7 @@ loop(KillSwitch) ->
5353
[Bin, Class, Term, Trace]),
5454
?MODULE:loop(KillSwitch)
5555
end;
56-
{timeout, _Timer, trigger_kill_switch} ->
56+
trigger_kill_switch ->
5757
logger:info("Tau kill switch activated. Shutting down....", []),
5858
init:stop();
5959
Any ->

app/server/beam/tau/src/tau_server/tau_server_api.erl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ start_link(CueServer, MIDIServer, LinkServer) ->
7474
init(Parent, CueServer, MIDIServer, LinkServer) ->
7575
register(?SERVER, self()),
7676
APIPort = application:get_env(?APPLICATION, api_port, undefined),
77-
DaemonPort = application:get_env(?APPLICATION, daemon_port, undefined),
78-
7977
logger:info("~n"
8078
"+--------------------------------------+~n"
8179
" This is the Sonic Pi API Server ~n"
@@ -87,7 +85,6 @@ init(Parent, CueServer, MIDIServer, LinkServer) ->
8785

8886
{ok, APISocket} = gen_udp:open(APIPort, [binary, {ip, loopback}]),
8987

90-
_KeepAlivePid = tau_keepalive:start(DaemonPort),
9188

9289
%% tell parent we have allocated resources and are up and running
9390
proc_lib:init_ack(Parent, {ok, self()}),

0 commit comments

Comments
 (0)