From 4fd6ecf53d0410d0922e6872a64406cb17e2cfbb Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:06:17 +0200 Subject: [PATCH 1/6] Improve AP error handling Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/activity_pub.ex | 4 ++++ lib/federation/activity_pub/actor.ex | 6 +++++- lib/federation/activity_pub/refresher.ex | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index a46a02cbb..66ffe52f7 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -101,6 +101,10 @@ defmodule Mobilizon.Federation.ActivityPub do {:existing, entity} -> handle_existing_entity(url, entity, options) + {:error, e} -> + Logger.warn("Something failed while fetching url #{inspect(e)}") + {:error, e} + e -> Logger.warn("Something failed while fetching url #{inspect(e)}") {:error, e} diff --git a/lib/federation/activity_pub/actor.ex b/lib/federation/activity_pub/actor.ex index aad2f2f6a..0cc3b589f 100644 --- a/lib/federation/activity_pub/actor.ex +++ b/lib/federation/activity_pub/actor.ex @@ -48,7 +48,8 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do @doc """ Create an actor locally by its URL (AP ID) """ - @spec make_actor_from_url(String.t(), boolean()) :: {:ok, %Actor{}} | {:error, any()} + @spec make_actor_from_url(String.t(), boolean()) :: + {:ok, %Actor{}} | {:error, :actor_deleted} | {:error, :http_error} | {:error, any()} def make_actor_from_url(url, preload \\ false) do if are_same_origin?(url, Endpoint.url()) do {:error, "Can't make a local actor from URL"} @@ -62,6 +63,9 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do Logger.info("Actor was deleted") {:error, :actor_deleted} + {:error, :http_error} -> + {:error, :http_error} + {:error, e} -> Logger.warn("Failed to make actor from url") {:error, e} diff --git a/lib/federation/activity_pub/refresher.ex b/lib/federation/activity_pub/refresher.ex index dec998427..8c466838c 100644 --- a/lib/federation/activity_pub/refresher.ex +++ b/lib/federation/activity_pub/refresher.ex @@ -60,6 +60,12 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do :ok <- fetch_collection(events_url, on_behalf_of) do :ok else + {:error, :actor_deleted} -> + {:error, :actor_deleted} + + {:error, :http_error} -> + {:error, :http_error} + {:error, err} -> Logger.error("Error while refreshing a group") @@ -68,6 +74,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do ) Logger.debug(inspect(err)) + {:error, err} err -> Logger.error("Error while refreshing a group") @@ -77,6 +84,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do ) Logger.debug(inspect(err)) + err end end From a2822750267d127a14e42a0bea7ca390eccfff72 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:06:27 +0200 Subject: [PATCH 2/6] Refresh group actors once per day Signed-off-by: Thomas Citharel --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index e99cea93a..40685256f 100644 --- a/config/config.exs +++ b/config/config.exs @@ -270,7 +270,7 @@ config :mobilizon, Oban, {Oban.Plugins.Cron, crontab: [ {"@hourly", Mobilizon.Service.Workers.BuildSiteMap, queue: :background}, - {"17 * * * *", Mobilizon.Service.Workers.RefreshGroups, queue: :background}, + {"17 4 * * *", Mobilizon.Service.Workers.RefreshGroups, queue: :background}, # To be activated in Mobilizon 1.2 # {"@hourly", Mobilizon.Service.Workers.CleanOrphanMediaWorker, queue: :background}, {"@hourly", Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker, queue: :background}, From b13d4d253e6478ae71b4edafd35cca0e08a70227 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:18:42 +0200 Subject: [PATCH 3/6] Increase tag allowed size Signed-off-by: Thomas Citharel --- lib/mobilizon/events/tag.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mobilizon/events/tag.ex b/lib/mobilizon/events/tag.ex index 3a2488e1e..b4fc428eb 100644 --- a/lib/mobilizon/events/tag.ex +++ b/lib/mobilizon/events/tag.ex @@ -36,7 +36,7 @@ defmodule Mobilizon.Events.Tag do |> TitleSlug.maybe_generate_slug() |> validate_required(@required_attrs) |> TitleSlug.unique_constraint() - |> validate_length(:title, min: 2, max: 20) - |> validate_length(:slug, min: 2, max: 20) + |> validate_length(:title, min: 2, max: 40) + |> validate_length(:slug, min: 2, max: 40) end end From 614ead1777bfb9309d2fc2528c67154484b10321 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:19:09 +0200 Subject: [PATCH 4/6] Transmogrifier event create Handle any type of error Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/transmogrifier.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/federation/activity_pub/transmogrifier.ex b/lib/federation/activity_pub/transmogrifier.ex index bf79f5ac2..e527ac915 100644 --- a/lib/federation/activity_pub/transmogrifier.ex +++ b/lib/federation/activity_pub/transmogrifier.ex @@ -111,8 +111,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do {:ok, activity, event} else {:existing_event, %Event{} = event} -> {:ok, nil, event} - {:error, _, _} -> :error - {:error, _} -> :error + _ -> :error end end From 4a1e9ce713f3fa7a0b4d4db2f09827b1596a2894 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Apr 2021 18:25:21 +0200 Subject: [PATCH 5/6] Add constraint on the comment url Signed-off-by: Thomas Citharel --- lib/mobilizon/discussions/comment.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mobilizon/discussions/comment.ex b/lib/mobilizon/discussions/comment.ex index bfa0cf6a1..8ec1bd75a 100644 --- a/lib/mobilizon/discussions/comment.ex +++ b/lib/mobilizon/discussions/comment.ex @@ -126,6 +126,7 @@ defmodule Mobilizon.Discussions.Comment do |> put_assoc(:media, Map.get(attrs, :media, [])) |> put_tags(attrs) |> put_mentions(attrs) + |> unique_constraint(:url, name: :comments_url_index) end @spec maybe_generate_uuid(Ecto.Changeset.t()) :: Ecto.Changeset.t() From 2692d32c5e59ff5a5d43b599d29a0fa691e29d62 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 29 Apr 2021 08:54:43 +0200 Subject: [PATCH 6/6] Add url to error log Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/activity_pub.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 66ffe52f7..0e11c056a 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -102,11 +102,11 @@ defmodule Mobilizon.Federation.ActivityPub do handle_existing_entity(url, entity, options) {:error, e} -> - Logger.warn("Something failed while fetching url #{inspect(e)}") + Logger.warn("Something failed while fetching url #{url} #{inspect(e)}") {:error, e} e -> - Logger.warn("Something failed while fetching url #{inspect(e)}") + Logger.warn("Something failed while fetching url #{url} #{inspect(e)}") {:error, e} end end