fix(workers): snooze incoming jobs while a host is backed off

With 5 attempts and Oban's short retry delays, an incoming activity from
an unknown actor on a backed-off host was discarded without a request.
ReceiverWorker and SignatureRetryWorker now snooze for up to 2 hours.
Also lowercase backoff host keys and log backed-off user fetches at debug.
This commit is contained in:
Lain Soykaf 2026-10-31 14:35:58 +04:00
commit b29d9d0981
No known key found for this signature in database
8 changed files with 97 additions and 13 deletions

View file

@ -67,6 +67,15 @@ defmodule Pleroma.HTTP.BackoffTest do
assert_ttl_about(300)
end
test "treats host names case-insensitively" do
mock_response(429)
assert {:error, :ratelimit} = Backoff.get("https://RateLimited.Example.com/users/alice")
assert_received :request
assert {:error, :ratelimit} = Backoff.get(@url)
refute_received :request
end
test "only backs off from the host that answered" do
mock_response(429)
assert {:error, :ratelimit} = Backoff.get(@url)

View file

@ -308,6 +308,7 @@ defmodule Pleroma.Web.WebFingerTest do
describe "rate limiting" do
setup do
# the module setup stubs NullCache, the backoff needs a real cache
Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy)
test_pid = self()

View file

@ -133,6 +133,28 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
end
end
describe "rate-limited fetches" do
setup do
Cachex.put(:http_backoff_cache, "ratelimited.example", true)
params =
insert(:note_activity).data
|> Map.put("actor", "https://ratelimited.example/users/alice")
%{args: %{"op" => "incoming_ap_doc", "params" => params}}
end
test "snooze while the actor's host is backed off", %{args: args} do
assert {:snooze, 300} = perform_job(ReceiverWorker, args)
end
test "stop snoozing two hours after the job was inserted", %{args: args} do
inserted_at = DateTime.add(DateTime.utc_now(), -121, :minute)
assert {:error, :ratelimit} = perform_job(ReceiverWorker, args, inserted_at: inserted_at)
end
end
test "cancels due to origin containment" do
params =
insert(:note_activity).data

View file

@ -306,6 +306,24 @@ defmodule Pleroma.Workers.SignatureRetryWorkerTest do
refute Activity.get_by_ap_id(create["id"])
end
test "snoozes while the payload actor's host is backed off" do
Cachex.put(:http_backoff_cache, "ratelimited.example", true)
alice = build(:user, local: false, ap_id: "https://ratelimited.example/users/alice")
params = %{
"type" => "Create",
"actor" => alice.ap_id,
"id" => "https://ratelimited.example/activities/1",
"object" => "https://ratelimited.example/objects/1"
}
job = failed_signature_job(params, signature_headers_for(alice))
assert {:snooze, 300} = SignatureRetryWorker.perform(job)
old_job = %{job | inserted_at: DateTime.add(DateTime.utc_now(), -121, :minute)}
assert {:error, :ratelimit} = SignatureRetryWorker.perform(old_job)
end
test "processes the activity after refetching a valid matching signature" do
alice = insert(:user, local: false, ap_id: "https://one.com/users/alice")