diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index b798eaa5a..c0173465a 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -8,8 +8,8 @@ defmodule Pleroma.HTTP.Connection do """ @hackney_options [ - timeout: 10000, - recv_timeout: 20000, + connect_timeout: 2_000, + recv_timeout: 20_000, follow_redirect: true, pool: :federation ] @@ -31,6 +31,10 @@ defmodule Pleroma.HTTP.Connection do # defp hackney_options(opts) do options = Keyword.get(opts, :adapter, []) - @hackney_options ++ options + adapter_options = Pleroma.Config.get([:http, :adapter], []) + + @hackney_options + |> Keyword.merge(adapter_options) + |> Keyword.merge(options) end end diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 26214ef3f..c5f720bc9 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -27,22 +27,29 @@ defmodule Pleroma.HTTP do """ def request(method, url, body \\ "", headers \\ [], options \\ []) do - options = - process_request_options(options) - |> process_sni_options(url) - |> process_adapter_options() + try do + options = + process_request_options(options) + |> process_sni_options(url) - params = Keyword.get(options, :params, []) + params = Keyword.get(options, :params, []) - %{} - |> Builder.method(method) - |> Builder.headers(headers) - |> Builder.opts(options) - |> Builder.url(url) - |> Builder.add_param(:body, :body, body) - |> Builder.add_param(:query, :query, params) - |> Enum.into([]) - |> (&Tesla.request(Connection.new(), &1)).() + %{} + |> Builder.method(method) + |> Builder.headers(headers) + |> Builder.opts(options) + |> Builder.url(url) + |> Builder.add_param(:body, :body, body) + |> Builder.add_param(:query, :query, params) + |> Enum.into([]) + |> (&Tesla.request(Connection.new(options), &1)).() + rescue + e -> + {:error, e} + catch + :exit, e -> + {:error, e} + end end defp process_sni_options(options, nil), do: options @@ -57,12 +64,6 @@ defmodule Pleroma.HTTP do end end - def process_adapter_options(options) do - adapter_options = Pleroma.Config.get([:http, :adapter], []) - - options ++ [adapter: adapter_options] - end - def process_request_options(options) do config = Application.get_env(:pleroma, :http, []) proxy = Keyword.get(config, :proxy_url, nil) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 8c58f4545..26921d386 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1452,7 +1452,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do url, [], adapter: [ - timeout: timeout, recv_timeout: timeout, pool: :default ] diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex index ab29a36e3..eaca41132 100644 --- a/lib/pleroma/web/rel_me.ex +++ b/lib/pleroma/web/rel_me.ex @@ -5,7 +5,6 @@ defmodule Pleroma.Web.RelMe do @hackney_options [ pool: :media, - timeout: 2_000, recv_timeout: 2_000, max_body: 2_000_000 ] diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 4341141df..4bd271d8e 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -11,7 +11,6 @@ defmodule Pleroma.Web.RichMedia.Parser do @hackney_options [ pool: :media, - timeout: 2_000, recv_timeout: 2_000, max_body: 2_000_000 ]