From 55cc1ba50eaea0df769604f0659aedf0d5969ecb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 19 Aug 2024 08:39:03 -0400 Subject: [PATCH 1/2] Fix test cases for validating instance reachability based on results of publishing attempts Now that we store the unreachable_since in the Oban job the value is no longer a %NaiveDateTime{} so the code was wrong --- test/pleroma/web/activity_pub/publisher_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 3acbac3969..99ed428777 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -180,7 +180,7 @@ test "publish to url with with different ports" do Publisher.prepare_one(%{ inbox: inbox, activity_id: activity.id, - unreachable_since: NaiveDateTime.utc_now() + unreachable_since: NaiveDateTime.utc_now() |> NaiveDateTime.to_string() }) |> Publisher.publish_one() @@ -269,7 +269,7 @@ test "publish to url with with different ports" do Publisher.prepare_one(%{ inbox: inbox, activity_id: activity.id, - unreachable_since: NaiveDateTime.utc_now() + unreachable_since: NaiveDateTime.utc_now() |> NaiveDateTime.to_string() }) |> Publisher.publish_one() end) =~ "connrefused" From 1b8141b506df1cc78e01f24881bed6257c9e5931 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sun, 18 Aug 2024 23:13:35 -0400 Subject: [PATCH 2/2] Address case where instance reachability status couldn't be updated --- changelog.d/publisher-reachability.fix | 1 + lib/pleroma/web/activity_pub/publisher.ex | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 changelog.d/publisher-reachability.fix diff --git a/changelog.d/publisher-reachability.fix b/changelog.d/publisher-reachability.fix new file mode 100644 index 0000000000..3f50be581b --- /dev/null +++ b/changelog.d/publisher-reachability.fix @@ -0,0 +1 @@ +Address case where instance reachability status couldn't be updated diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 5cd982c6a2..0de3a0d434 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -148,12 +148,17 @@ def publish_one(%Prepared{} = p) do {"digest", p.digest} ] ) do - maybe_set_reachable(p.unreachable_since, p.inbox) + if not is_nil(p.unreachable_since) do + Instances.set_reachable(p.inbox) + end result else {_post_result, %{status: code} = response} = e -> - maybe_set_unreachable(p.unreachable_since, p.inbox) + if is_nil(p.unreachable_since) do + Instances.set_unreachable(p.inbox) + end + Logger.metadata(activity: p.activity_id, inbox: p.inbox, status: code) Logger.error("Publisher failed to inbox #{p.inbox} with status #{code}") @@ -174,7 +179,10 @@ def publish_one(%Prepared{} = p) do connection_pool_snooze() e -> - maybe_set_unreachable(p.unreachable_since, p.inbox) + if is_nil(p.unreachable_since) do + Instances.set_unreachable(p.inbox) + end + Logger.metadata(activity: p.activity_id, inbox: p.inbox) Logger.error("Publisher failed to inbox #{p.inbox} #{inspect(e)}") {:error, e} @@ -183,12 +191,6 @@ def publish_one(%Prepared{} = p) do defp connection_pool_snooze, do: {:snooze, 3} - defp maybe_set_reachable(%NaiveDateTime{}, inbox), do: Instances.set_reachable(inbox) - defp maybe_set_reachable(_, _), do: :ok - - defp maybe_set_unreachable(nil, inbox), do: Instances.set_unreachable(inbox) - defp maybe_set_unreachable(%NaiveDateTime{}, _), do: :ok - defp signature_host(%URI{port: port, scheme: scheme, host: host}) do if port == URI.default_port(scheme) do host