Skip to content

Commit

Permalink
Catch all errors in connect/2 (#209)
Browse files Browse the repository at this point in the history
* add failing test

* mark test slow

* sleep less

* add fix

* changelog
  • Loading branch information
ruslandoga authored Nov 2, 2024
1 parent ca21639 commit 6a46a89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- catch all errors in `connect/1` to avoid triggering Supervisor https://github.com/plausible/ch/pull/209

## 0.2.8 (2024-09-06)

- support named tuples https://github.com/plausible/ch/pull/197
Expand Down
2 changes: 2 additions & 0 deletions lib/ch/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ defmodule Ch.Connection do
{:error, reason}
end
end
catch
_kind, reason -> {:error, reason}
end

@impl true
Expand Down
22 changes: 22 additions & 0 deletions test/ch/connect_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Ch.ConnectTest do
use ExUnit.Case
import ExUnit.CaptureLog

@tag :slow
test "retries to connect even with exceptions" do
# See https://github.com/plausible/ch/issues/208
bad_transport_opts = [sndbuf: nil]

logs =
capture_log(fn ->
{:ok, conn} =
Ch.start_link(database: Ch.Test.database(), transport_opts: bad_transport_opts)

:timer.sleep(100)

assert Process.alive?(conn)
end)

assert logs =~ "failed to connect: ** (ArgumentError) argument error"
end
end

0 comments on commit 6a46a89

Please sign in to comment.