Spaces:
Sleeping
Sleeping
hiett
commited on
Commit
·
28b00d6
1
Parent(s):
739b573
Begin work ensuring that the pool is correctly being destroyed on connection failures
Browse files
lib/srh/http/command_handler.ex
CHANGED
@@ -169,12 +169,20 @@ defmodule Srh.Http.CommandHandler do
|
|
169 |
when is_number(max_connections) do
|
170 |
case GenRegistry.lookup_or_start(Client, srh_id, [max_connections, connection_info]) do
|
171 |
{:ok, pid} ->
|
|
|
|
|
172 |
# Run the command
|
173 |
case Client.find_worker(pid)
|
174 |
|> ClientWorker.redis_command(command_array) do
|
175 |
{:ok, res} ->
|
176 |
{:ok, %{result: res}}
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
{:error, error} ->
|
179 |
decode_error(error, srh_id)
|
180 |
end
|
|
|
169 |
when is_number(max_connections) do
|
170 |
case GenRegistry.lookup_or_start(Client, srh_id, [max_connections, connection_info]) do
|
171 |
{:ok, pid} ->
|
172 |
+
IO.puts("SRH: Found client #{inspect(pid)}")
|
173 |
+
|
174 |
# Run the command
|
175 |
case Client.find_worker(pid)
|
176 |
|> ClientWorker.redis_command(command_array) do
|
177 |
{:ok, res} ->
|
178 |
{:ok, %{result: res}}
|
179 |
|
180 |
+
# Jedix connection error
|
181 |
+
{:error, %{reason: :closed} = error} ->
|
182 |
+
# Ensure that this pool is killed, but still pass the error up the chain for the response
|
183 |
+
Client.destroy_workers(pid)
|
184 |
+
decode_error(error, srh_id)
|
185 |
+
|
186 |
{:error, error} ->
|
187 |
decode_error(error, srh_id)
|
188 |
end
|
lib/srh/redis/client.ex
CHANGED
@@ -35,6 +35,10 @@ defmodule Srh.Redis.Client do
|
|
35 |
GenServer.cast(client, {:return_worker, pid})
|
36 |
end
|
37 |
|
|
|
|
|
|
|
|
|
38 |
def handle_call({:find_worker}, _from, %{registry_pid: registry_pid} = state)
|
39 |
when is_pid(registry_pid) do
|
40 |
{:ok, worker} = ClientRegistry.find_worker(registry_pid)
|
@@ -59,13 +63,17 @@ defmodule Srh.Redis.Client do
|
|
59 |
{:noreply, state}
|
60 |
end
|
61 |
|
|
|
|
|
|
|
|
|
|
|
62 |
def handle_cast(_msg, state) do
|
63 |
{:noreply, state}
|
64 |
end
|
65 |
|
66 |
def handle_info(:idle_death, state) do
|
67 |
ClientRegistry.destroy_workers(state.registry_pid)
|
68 |
-
|
69 |
{:stop, :normal, state}
|
70 |
end
|
71 |
|
|
|
35 |
GenServer.cast(client, {:return_worker, pid})
|
36 |
end
|
37 |
|
38 |
+
def destroy_workers(client) do
|
39 |
+
GenServer.cast(client, {:destroy_workers})
|
40 |
+
end
|
41 |
+
|
42 |
def handle_call({:find_worker}, _from, %{registry_pid: registry_pid} = state)
|
43 |
when is_pid(registry_pid) do
|
44 |
{:ok, worker} = ClientRegistry.find_worker(registry_pid)
|
|
|
63 |
{:noreply, state}
|
64 |
end
|
65 |
|
66 |
+
def handle_cast({:destroy_workers}, state) do
|
67 |
+
ClientRegistry.destroy_workers(state.registry_pid)
|
68 |
+
{:stop, :normal, state}
|
69 |
+
end
|
70 |
+
|
71 |
def handle_cast(_msg, state) do
|
72 |
{:noreply, state}
|
73 |
end
|
74 |
|
75 |
def handle_info(:idle_death, state) do
|
76 |
ClientRegistry.destroy_workers(state.registry_pid)
|
|
|
77 |
{:stop, :normal, state}
|
78 |
end
|
79 |
|
lib/srh/redis/client_registry.ex
CHANGED
@@ -33,6 +33,8 @@ defmodule Srh.Redis.ClientRegistry do
|
|
33 |
end
|
34 |
|
35 |
def destroy_workers(registry) do
|
|
|
|
|
36 |
GenServer.cast(registry, {:destroy_workers})
|
37 |
end
|
38 |
|
|
|
33 |
end
|
34 |
|
35 |
def destroy_workers(registry) do
|
36 |
+
# TODO: remove before shipping
|
37 |
+
IO.puts("DEBUG: Destroying workers")
|
38 |
GenServer.cast(registry, {:destroy_workers})
|
39 |
end
|
40 |
|