Skip to content

Commit 60c1073

Browse files
authored
Merge pull request #126 from SophisticaSean/sophisticasean/helpful-checkout-timeout-error-message
Add helpful checkout timeout error
2 parents ab67d8f + a4babdb commit 60c1073

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

lib/finch/http1/pool.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,23 @@ defmodule Finch.HTTP1.Pool do
5454
catch
5555
:exit, data ->
5656
Telemetry.exception(:queue, start_time, :exit, data, __STACKTRACE__, metadata)
57-
exit(data)
57+
58+
# Provide helpful error messages for known errors
59+
case data do
60+
{:timeout, {NimblePool, :checkout, _affected_pids}} ->
61+
reraise(
62+
"""
63+
Finch was unable to provide a connection within the timeout due to excess queuing \
64+
for connections. Consider adjusting the pool size, count, timeout or reducing the \
65+
rate of requests if it is possible that the downstream service is unable to keep up \
66+
with the current rate.
67+
""",
68+
__STACKTRACE__
69+
)
70+
71+
_ ->
72+
exit(data)
73+
end
5874
end
5975
end
6076

test/finch/telemetry_test.exs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,14 @@ defmodule Finch.TelemetryTest do
230230

231231
Bypass.down(bypass)
232232

233-
try do
234-
Finch.build(:get, endpoint(bypass)) |> Finch.request(finch_name, pool_timeout: 0)
235-
catch
236-
:exit, reason ->
237-
assert {:timeout, _} = reason
238-
end
233+
assert_raise RuntimeError,
234+
~r/Finch was unable to provide a connection within the timeout/,
235+
fn ->
236+
Finch.build(:get, endpoint(bypass))
237+
|> Finch.request(finch_name, pool_timeout: 0)
238+
end
239239

240240
assert_receive {^ref, :start}
241-
assert_receive {^ref, :exception}
242241

243242
:telemetry.detach(to_string(finch_name))
244243
end
@@ -295,12 +294,12 @@ defmodule Finch.TelemetryTest do
295294

296295
Bypass.down(bypass)
297296

298-
try do
299-
Finch.build(:get, endpoint(bypass)) |> Finch.request(finch_name, pool_timeout: 0)
300-
catch
301-
:exit, reason ->
302-
assert {:timeout, _} = reason
303-
end
297+
assert_raise RuntimeError,
298+
~r/Finch was unable to provide a connection within the timeout/,
299+
fn ->
300+
Finch.build(:get, endpoint(bypass))
301+
|> Finch.request(finch_name, pool_timeout: 0)
302+
end
304303

305304
assert_receive {^ref, :start}
306305
assert_receive {^ref, :exception}

test/finch_test.exs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,12 @@ defmodule FinchTest do
516516

517517
:sys.suspend(finch_name)
518518

519-
assert {:timeout, _} =
520-
catch_exit(
521-
Finch.build(:get, endpoint(bypass))
522-
|> Finch.request(finch_name, pool_timeout: 0)
523-
)
519+
assert_raise RuntimeError,
520+
~r/Finch was unable to provide a connection within the timeout/,
521+
fn ->
522+
Finch.build(:get, endpoint(bypass))
523+
|> Finch.request(finch_name, pool_timeout: 0)
524+
end
524525

525526
:sys.resume(finch_name)
526527

0 commit comments

Comments
 (0)