mirror of https://github.com/Chocobozzz/PeerTube
Use a global request timeout
parent
3d470a530c
commit
7500d6c900
|
@ -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<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'>
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<T> = (items: T[]) => (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)
|
||||
|
||||
const options = {
|
||||
activityPub: true,
|
||||
timeout: REQUEST_TIMEOUT
|
||||
}
|
||||
const options = { activityPub: true }
|
||||
|
||||
const startDate = new Date()
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue