summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-07-24 15:42:50 -0400
committerMark Felder <feld@feld.me>2024-07-24 15:42:50 -0400
commit731f7b87d24bd58d5349c7d1f564cd73dbf59aa9 (patch)
tree77ec65363094f446bf8958b43309ef6d5ebdb36d
parent858fd01c012a48928b55999e8209371a5049c3e6 (diff)
downloadpleroma-731f7b87d24bd58d5349c7d1f564cd73dbf59aa9.tar.gz
pleroma-731f7b87d24bd58d5349c7d1f564cd73dbf59aa9.zip
Pad RichMediaWorker timeout to be 2s longer than the Rich Media HTTP timeout
-rw-r--r--config/config.exs2
-rw-r--r--lib/pleroma/web/rich_media/helpers.ex5
-rw-r--r--lib/pleroma/workers/rich_media_worker.ex10
3 files changed, 14 insertions, 3 deletions
diff --git a/config/config.exs b/config/config.exs
index 044f951f6..a370405e0 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -448,7 +448,7 @@ config :pleroma, :rich_media,
Pleroma.Web.RichMedia.Parsers.TwitterCard,
Pleroma.Web.RichMedia.Parsers.OEmbed
],
- failure_backoff: 60_000,
+ timeout: 5_000,
ttl_setters: [
Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl,
Pleroma.Web.RichMedia.Parser.TTL.Opengraph
diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex
index fba23c657..e2889b351 100644
--- a/lib/pleroma/web/rich_media/helpers.ex
+++ b/lib/pleroma/web/rich_media/helpers.ex
@@ -69,9 +69,12 @@ defmodule Pleroma.Web.RichMedia.Helpers do
end
defp http_options do
+ timeout = Config.get!([:rich_media, :timeout])
+
[
pool: :rich_media,
- max_body: Config.get([:rich_media, :max_body], 5_000_000)
+ max_body: Config.get([:rich_media, :max_body], 5_000_000),
+ tesla_middleware: [{Tesla.Middleware.Timeout, timeout: timeout}]
]
end
end
diff --git a/lib/pleroma/workers/rich_media_worker.ex b/lib/pleroma/workers/rich_media_worker.ex
index 30f9d9e9e..0a1c6d58c 100644
--- a/lib/pleroma/workers/rich_media_worker.ex
+++ b/lib/pleroma/workers/rich_media_worker.ex
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.RichMediaWorker do
+ alias Pleroma.Config
alias Pleroma.Web.RichMedia.Backfill
alias Pleroma.Web.RichMedia.Card
@@ -31,6 +32,13 @@ defmodule Pleroma.Workers.RichMediaWorker do
end
end
+ # There is timeout value enforced by Tesla.Middleware.Timeout
+ # which can be found in the RichMedia.Helpers module to allow us to detect
+ # a slow/infinite data stream and insert a negative cache entry for the URL
+ # We pad it by 2 seconds to be certain a slow connection is detected and we
+ # can inject a negative cache entry for the URL
@impl Oban.Worker
- def timeout(_job), do: :timer.seconds(5)
+ def timeout(_job) do
+ Config.get!([:rich_media, :timeout]) + :timer.seconds(2)
+ end
end