summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2024-08-19 16:49:08 +0000
committerfeld <feld@feld.me>2024-08-19 16:49:08 +0000
commit08a444f6c3591fec60d11638587c60c5dc417a48 (patch)
treeb90bb7bfd8986c1d0a4086f3b1f63436caa3c758
parent12d682c62f45917182ca22b4ce8c7a98d8a9b4dd (diff)
parent1b8141b506df1cc78e01f24881bed6257c9e5931 (diff)
downloadpleroma-08a444f6c3591fec60d11638587c60c5dc417a48.tar.gz
pleroma-08a444f6c3591fec60d11638587c60c5dc417a48.zip
Merge branch 'reachability' into 'develop'
Fix reachability based on results of publishing attempts See merge request pleroma/pleroma!4231
-rw-r--r--changelog.d/publisher-reachability.fix1
-rw-r--r--lib/pleroma/web/activity_pub/publisher.ex20
-rw-r--r--test/pleroma/web/activity_pub/publisher_test.exs4
3 files changed, 14 insertions, 11 deletions
diff --git a/changelog.d/publisher-reachability.fix b/changelog.d/publisher-reachability.fix
new file mode 100644
index 000000000..3f50be581
--- /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 5cd982c6a..0de3a0d43 100644
--- a/lib/pleroma/web/activity_pub/publisher.ex
+++ b/lib/pleroma/web/activity_pub/publisher.ex
@@ -148,12 +148,17 @@ defmodule Pleroma.Web.ActivityPub.Publisher 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 @@ defmodule Pleroma.Web.ActivityPub.Publisher 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 @@ defmodule Pleroma.Web.ActivityPub.Publisher 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
diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs
index 3acbac396..99ed42877 100644
--- a/test/pleroma/web/activity_pub/publisher_test.exs
+++ b/test/pleroma/web/activity_pub/publisher_test.exs
@@ -180,7 +180,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest 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"