Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions lib/ch/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ defmodule Ch.Connection do
@impl true
@spec ping(conn) :: {:ok, conn} | {:disconnect, Mint.Types.error() | Error.t(), conn}
def ping(conn) do
conn = maybe_reconnect(conn)
headers = [{"user-agent", @user_agent}]

case request(conn, "GET", "/ping", headers, _body = "", _opts = []) do
Expand Down Expand Up @@ -103,10 +102,8 @@ defmodule Ch.Connection do

@impl true
def handle_declare(query, params, opts, conn) do
conn = maybe_reconnect(conn)
%Query{command: command, decode: decode} = query
{query_params, extra_headers, body} = params

path = path(conn, query_params, opts)
headers = headers(conn, extra_headers, opts)
timeout = timeout(conn, opts)
Expand Down Expand Up @@ -267,7 +264,6 @@ defmodule Ch.Connection do

@impl true
def handle_execute(%Query{} = query, {:stream, params}, opts, conn) do
conn = maybe_reconnect(conn)
{query_params, extra_headers, body} = params

path = path(conn, query_params, opts)
Expand Down Expand Up @@ -300,7 +296,6 @@ defmodule Ch.Connection do
end

def handle_execute(%Query{command: :insert} = query, params, opts, conn) do
conn = maybe_reconnect(conn)
{query_params, extra_headers, body} = params

path = path(conn, query_params, opts)
Expand All @@ -319,9 +314,7 @@ defmodule Ch.Connection do
end

def handle_execute(query, params, opts, conn) do
conn = maybe_reconnect(conn)
{query_params, extra_headers, body} = params

path = path(conn, query_params, opts)
headers = headers(conn, extra_headers, opts)

Expand Down Expand Up @@ -482,28 +475,6 @@ defmodule Ch.Connection do
"/?" <> URI.encode_query(settings ++ query_params)
end

# If the http connection was closed by the server, attempt to
# reconnect once. If the re-connect failed, return the old
# connection and let the error bubble up to the caller.
defp maybe_reconnect(conn) do
if HTTP.open?(conn) do
conn
else
opts = HTTP.get_private(conn, :connect_options)

with {:ok, new_conn} <- do_connect(opts) do
Logger.warning(
"The connection was closed by the server; a new connection has been successfully reestablished."
)

# copy settings that are set dynamically (e.g. json as text) over to the new connection
maybe_put_private(new_conn, :settings, HTTP.get_private(conn, :settings))
else
_ -> conn
end
end
end

defp do_connect(opts) do
scheme = String.to_existing_atom(opts[:scheme] || "http")
address = opts[:hostname] || "localhost"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Ch.MixProject do
use Mix.Project

@source_url "https://github.com/plausible/ch"
@version "0.6.1"
@version "0.6.2-alpha.1"

def project do
[
Expand Down