From 2735256504cf4cfe05312207a9a755e3dc64fdcc Mon Sep 17 00:00:00 2001 From: Kaleb Bozorgzadeh Date: Wed, 16 Sep 2020 15:05:44 -0600 Subject: [PATCH] Correct timeout and backoff functionality. Connect callback must return :error --- lib/scrub/session.ex | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/scrub/session.ex b/lib/scrub/session.ex index 9568a1e..228ef02 100644 --- a/lib/scrub/session.ex +++ b/lib/scrub/session.ex @@ -33,17 +33,19 @@ defmodule Scrub.Session do socket_opts \\ [], timeout \\ 15000, pool_size \\ @default_pool_size, - idle_interval \\ @default_idle_interval + idle_interval \\ @default_idle_interval, + backoff_type \\ :exp ) - def start_link(host, port, opts, timeout, pool_size, idle_interval) do + def start_link(host, port, opts, timeout, pool_size, idle_interval, backoff_type) do opts = [ hostname: host, port: port, timeout: timeout, pool_size: pool_size, - idle_interval: idle_interval + idle_interval: idle_interval, + backoff_type: backoff_type ] ++ opts DBConnection.start_link(__MODULE__, opts) @@ -129,7 +131,7 @@ defmodule Scrub.Session do def connect(opts) do host = Keyword.fetch!(opts, :hostname) |> String.to_charlist() port = Keyword.fetch!(opts, :port) - timeout = Keyword.get(opts, :connect_timeout, 5_000) + timeout = Keyword.get(opts, :timeout, 5_000) enforced_opts = [packet: :raw, mode: :binary, active: false, keepalive: true] socket_opts = Keyword.get(opts, :socket_options, []) @@ -315,7 +317,8 @@ defmodule Scrub.Session do error -> Logger.error("Error: #{inspect(error)}") :gen_tcp.close(socket) - {:backoff, 1000, %{s | socket: nil}} + # return error and let DBConnection backoff + {:error, error} end end @@ -338,7 +341,8 @@ defmodule Scrub.Session do error -> Logger.error("Error: #{inspect(error)}") :gen_tcp.close(socket) - {:backoff, 1000, %{s | socket: nil}} + # return error and let DBConnection backoff + {:error, error} end end @@ -397,7 +401,8 @@ defmodule Scrub.Session do error -> Logger.error("Error: #{inspect(error)}") :gen_tcp.close(socket) - {:backoff, 1000, %{s | socket: nil}} + # return error and let DBConnection backoff + {:error, error} end end