diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index fd2a56f30..d3c83d26e 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -2,7 +2,7 @@ import { createWriteStream, remove } from 'fs-extra' import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' import { join } from 'path' import { CONFIG } from '../initializers/config' -import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' +import { ACTIVITY_PUB, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants' import { pipelinePromise } from './core-utils' import { processImage } from './image-utils' import { logger } from './logger' @@ -24,6 +24,7 @@ type PeerTubeRequestOptions = { key: string headers: string[] } + timeout?: number jsonResponse?: boolean } & Pick @@ -92,6 +93,10 @@ const peertubeGot = got.extend({ path }, httpSignatureOptions) } + }, + + (options: GotOptions) => { + options.timeout = REQUEST_TIMEOUT } ] } @@ -182,6 +187,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) { method: options.method, json: options.json, searchParams: options.searchParams, + timeout: options.timeout ?? REQUEST_TIMEOUT, headers, context } diff --git a/server/lib/activitypub/actors/webfinger.ts b/server/lib/activitypub/actors/webfinger.ts index cf8eddfc7..723fca586 100644 --- a/server/lib/activitypub/actors/webfinger.ts +++ b/server/lib/activitypub/actors/webfinger.ts @@ -1,7 +1,7 @@ import * as WebFinger from 'webfinger.js' import { isTestInstance } from '@server/helpers/core-utils' import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' -import { WEBSERVER } from '@server/initializers/constants' +import { REQUEST_TIMEOUT, WEBSERVER } from '@server/initializers/constants' import { ActorModel } from '@server/models/actor/actor' import { MActorFull } from '@server/types/models' import { WebFingerData } from '@shared/models' @@ -10,7 +10,7 @@ const webfinger = new WebFinger({ webfist_fallback: false, tls_only: isTestInstance(), uri_fallback: false, - request_timeout: 3000 + request_timeout: REQUEST_TIMEOUT }) async function loadActorUrlOrGetFromWebfinger (uriArg: string) { diff --git a/server/lib/activitypub/crawl.ts b/server/lib/activitypub/crawl.ts index 278abf7de..cd117f571 100644 --- a/server/lib/activitypub/crawl.ts +++ b/server/lib/activitypub/crawl.ts @@ -3,7 +3,7 @@ import { URL } from 'url' import { ActivityPubOrderedCollection } from '../../../shared/models/activitypub' import { logger } from '../../helpers/logger' import { doJSONRequest } from '../../helpers/requests' -import { ACTIVITY_PUB, REQUEST_TIMEOUT, WEBSERVER } from '../../initializers/constants' +import { ACTIVITY_PUB, WEBSERVER } from '../../initializers/constants' type HandlerFunction = (items: T[]) => (Promise | Bluebird) type CleanerFunction = (startedDate: Date) => (Promise | Bluebird) @@ -13,10 +13,7 @@ async function crawlCollectionPage (argUrl: string, handler: HandlerFunction logger.info('Crawling ActivityPub data on %s.', url) - const options = { - activityPub: true, - timeout: REQUEST_TIMEOUT - } + const options = { activityPub: true } const startDate = new Date() diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts index c69ff9e83..d4b328635 100644 --- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts +++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts @@ -3,7 +3,7 @@ import * as Bull from 'bull' import { ActivitypubHttpBroadcastPayload } from '@shared/models' import { logger } from '../../../helpers/logger' import { doRequest } from '../../../helpers/requests' -import { BROADCAST_CONCURRENCY, REQUEST_TIMEOUT } from '../../../initializers/constants' +import { BROADCAST_CONCURRENCY } from '../../../initializers/constants' import { ActorFollowScoreCache } from '../../files-cache' import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' @@ -19,7 +19,6 @@ async function processActivityPubHttpBroadcast (job: Bull.Job) { method: 'POST' as 'POST', json: body, httpSignature: httpSignatureOptions, - timeout: REQUEST_TIMEOUT, headers: buildGlobalHeaders(body) } diff --git a/server/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/lib/job-queue/handlers/activitypub-http-unicast.ts index 585dad671..9e561c6b7 100644 --- a/server/lib/job-queue/handlers/activitypub-http-unicast.ts +++ b/server/lib/job-queue/handlers/activitypub-http-unicast.ts @@ -2,7 +2,6 @@ import * as Bull from 'bull' import { ActivitypubHttpUnicastPayload } from '@shared/models' import { logger } from '../../../helpers/logger' import { doRequest } from '../../../helpers/requests' -import { REQUEST_TIMEOUT } from '../../../initializers/constants' import { ActorFollowScoreCache } from '../../files-cache' import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' @@ -19,7 +18,6 @@ async function processActivityPubHttpUnicast (job: Bull.Job) { method: 'POST' as 'POST', json: body, httpSignature: httpSignatureOptions, - timeout: REQUEST_TIMEOUT, headers: buildGlobalHeaders(body) }