Pad RichMediaWorker timeout to be 2s longer than the Rich Media HTTP timeout

This commit is contained in:
Mark Felder 2024-07-24 15:42:50 -04:00
parent 858fd01c01
commit 731f7b87d2
3 changed files with 14 additions and 3 deletions

View File

@ -448,7 +448,7 @@ config :pleroma, :rich_media,
Pleroma.Web.RichMedia.Parsers.TwitterCard, Pleroma.Web.RichMedia.Parsers.TwitterCard,
Pleroma.Web.RichMedia.Parsers.OEmbed Pleroma.Web.RichMedia.Parsers.OEmbed
], ],
failure_backoff: 60_000, timeout: 5_000,
ttl_setters: [ ttl_setters: [
Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl, Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl,
Pleroma.Web.RichMedia.Parser.TTL.Opengraph Pleroma.Web.RichMedia.Parser.TTL.Opengraph

View File

@ -69,9 +69,12 @@ defmodule Pleroma.Web.RichMedia.Helpers do
end end
defp http_options do defp http_options do
timeout = Config.get!([:rich_media, :timeout])
[ [
pool: :rich_media, 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
end end

View File

@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.RichMediaWorker do defmodule Pleroma.Workers.RichMediaWorker do
alias Pleroma.Config
alias Pleroma.Web.RichMedia.Backfill alias Pleroma.Web.RichMedia.Backfill
alias Pleroma.Web.RichMedia.Card alias Pleroma.Web.RichMedia.Card
@ -31,6 +32,13 @@ defmodule Pleroma.Workers.RichMediaWorker do
end end
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 @impl Oban.Worker
def timeout(_job), do: :timer.seconds(5) def timeout(_job) do
Config.get!([:rich_media, :timeout]) + :timer.seconds(2)
end
end end