Use a global request timeout

pull/4161/head
Chocobozzz 2021-06-14 18:06:58 +02:00
parent 3d470a530c
commit 7500d6c900
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 12 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import { createWriteStream, remove } from 'fs-extra'
import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got'
import { join } from 'path' import { join } from 'path'
import { CONFIG } from '../initializers/config' 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 { pipelinePromise } from './core-utils'
import { processImage } from './image-utils' import { processImage } from './image-utils'
import { logger } from './logger' import { logger } from './logger'
@ -24,6 +24,7 @@ type PeerTubeRequestOptions = {
key: string key: string
headers: string[] headers: string[]
} }
timeout?: number
jsonResponse?: boolean jsonResponse?: boolean
} & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'> } & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'>
@ -92,6 +93,10 @@ const peertubeGot = got.extend({
path path
}, httpSignatureOptions) }, httpSignatureOptions)
} }
},
(options: GotOptions) => {
options.timeout = REQUEST_TIMEOUT
} }
] ]
} }
@ -182,6 +187,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
method: options.method, method: options.method,
json: options.json, json: options.json,
searchParams: options.searchParams, searchParams: options.searchParams,
timeout: options.timeout ?? REQUEST_TIMEOUT,
headers, headers,
context context
} }

View File

@ -1,7 +1,7 @@
import * as WebFinger from 'webfinger.js' import * as WebFinger from 'webfinger.js'
import { isTestInstance } from '@server/helpers/core-utils' import { isTestInstance } from '@server/helpers/core-utils'
import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 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 { ActorModel } from '@server/models/actor/actor'
import { MActorFull } from '@server/types/models' import { MActorFull } from '@server/types/models'
import { WebFingerData } from '@shared/models' import { WebFingerData } from '@shared/models'
@ -10,7 +10,7 @@ const webfinger = new WebFinger({
webfist_fallback: false, webfist_fallback: false,
tls_only: isTestInstance(), tls_only: isTestInstance(),
uri_fallback: false, uri_fallback: false,
request_timeout: 3000 request_timeout: REQUEST_TIMEOUT
}) })
async function loadActorUrlOrGetFromWebfinger (uriArg: string) { async function loadActorUrlOrGetFromWebfinger (uriArg: string) {

View File

@ -3,7 +3,7 @@ import { URL } from 'url'
import { ActivityPubOrderedCollection } from '../../../shared/models/activitypub' import { ActivityPubOrderedCollection } from '../../../shared/models/activitypub'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import { doJSONRequest } from '../../helpers/requests' import { doJSONRequest } from '../../helpers/requests'
import { ACTIVITY_PUB, REQUEST_TIMEOUT, WEBSERVER } from '../../initializers/constants' import { ACTIVITY_PUB, WEBSERVER } from '../../initializers/constants'
type HandlerFunction<T> = (items: T[]) => (Promise<any> | Bluebird<any>) type HandlerFunction<T> = (items: T[]) => (Promise<any> | Bluebird<any>)
type CleanerFunction = (startedDate: Date) => (Promise<any> | Bluebird<any>) type CleanerFunction = (startedDate: Date) => (Promise<any> | Bluebird<any>)
@ -13,10 +13,7 @@ async function crawlCollectionPage <T> (argUrl: string, handler: HandlerFunction
logger.info('Crawling ActivityPub data on %s.', url) logger.info('Crawling ActivityPub data on %s.', url)
const options = { const options = { activityPub: true }
activityPub: true,
timeout: REQUEST_TIMEOUT
}
const startDate = new Date() const startDate = new Date()

View File

@ -3,7 +3,7 @@ import * as Bull from 'bull'
import { ActivitypubHttpBroadcastPayload } from '@shared/models' import { ActivitypubHttpBroadcastPayload } from '@shared/models'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { doRequest } from '../../../helpers/requests' 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 { ActorFollowScoreCache } from '../../files-cache'
import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
@ -19,7 +19,6 @@ async function processActivityPubHttpBroadcast (job: Bull.Job) {
method: 'POST' as 'POST', method: 'POST' as 'POST',
json: body, json: body,
httpSignature: httpSignatureOptions, httpSignature: httpSignatureOptions,
timeout: REQUEST_TIMEOUT,
headers: buildGlobalHeaders(body) headers: buildGlobalHeaders(body)
} }

View File

@ -2,7 +2,6 @@ import * as Bull from 'bull'
import { ActivitypubHttpUnicastPayload } from '@shared/models' import { ActivitypubHttpUnicastPayload } from '@shared/models'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { doRequest } from '../../../helpers/requests' import { doRequest } from '../../../helpers/requests'
import { REQUEST_TIMEOUT } from '../../../initializers/constants'
import { ActorFollowScoreCache } from '../../files-cache' import { ActorFollowScoreCache } from '../../files-cache'
import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
@ -19,7 +18,6 @@ async function processActivityPubHttpUnicast (job: Bull.Job) {
method: 'POST' as 'POST', method: 'POST' as 'POST',
json: body, json: body,
httpSignature: httpSignatureOptions, httpSignature: httpSignatureOptions,
timeout: REQUEST_TIMEOUT,
headers: buildGlobalHeaders(body) headers: buildGlobalHeaders(body)
} }