From 6502c3d43e512e968ad49f5a3bc9abc302471e18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Jan 2018 10:02:11 +0100 Subject: Avoid making retried requests to dead followers --- .../activitypub-http-job-scheduler.ts | 7 +++++++ .../activitypub-http-unicast-handler.ts | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'server/lib/jobs') diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts index 10423a7df..4459152db 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts @@ -4,6 +4,7 @@ import { logger } from '../../../helpers/logger' import { getServerActor } from '../../../helpers/utils' import { ACTIVITY_PUB } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { JobHandler, JobScheduler } from '../job-scheduler' import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' @@ -35,6 +36,12 @@ async function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPaylo if (attemptNumber < ACTIVITY_PUB.MAX_HTTP_ATTEMPT) { logger.debug('Retrying request to %s (attempt %d/%d).', uri, attemptNumber, ACTIVITY_PUB.MAX_HTTP_ATTEMPT, err) + const actor = await ActorFollowModel.loadByFollowerInbox(uri, undefined) + if (!actor) { + logger.debug('Actor %s is not a follower, do not retry the request.', uri) + return false + } + const newPayload = Object.assign(payload, { uris: [ uri ], attemptNumber diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts index deedf8402..54a7504e8 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts @@ -6,10 +6,11 @@ import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRe async function process (payload: ActivityPubHttpPayload, jobId: number) { logger.info('Processing ActivityPub unicast in job %d.', jobId) + const uri = payload.uris[0] + const body = await computeBody(payload) const httpSignatureOptions = await buildSignedRequestOptions(payload) - const uri = payload.uris[0] const options = { method: 'POST', uri, -- cgit v1.2.3