aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-14 18:06:58 +0200
committerChocobozzz <me@florianbigard.com>2021-06-15 08:21:31 +0200
commit7500d6c9000b531fda1fd64e188b7cf83803941a (patch)
tree4329c72654b0d6526366cf47de588b7c7d72e073 /server
parent3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4 (diff)
downloadPeerTube-7500d6c9000b531fda1fd64e188b7cf83803941a.tar.gz
PeerTube-7500d6c9000b531fda1fd64e188b7cf83803941a.tar.zst
PeerTube-7500d6c9000b531fda1fd64e188b7cf83803941a.zip
Use a global request timeout
Diffstat (limited to 'server')
-rw-r--r--server/helpers/requests.ts8
-rw-r--r--server/lib/activitypub/actors/webfinger.ts4
-rw-r--r--server/lib/activitypub/crawl.ts7
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-broadcast.ts3
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-unicast.ts2
5 files changed, 12 insertions, 12 deletions
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'
2import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got' 2import got, { CancelableRequest, Options as GotOptions, RequestError } from 'got'
3import { join } from 'path' 3import { join } from 'path'
4import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
5import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' 5import { ACTIVITY_PUB, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants'
6import { pipelinePromise } from './core-utils' 6import { pipelinePromise } from './core-utils'
7import { processImage } from './image-utils' 7import { processImage } from './image-utils'
8import { logger } from './logger' 8import { logger } from './logger'
@@ -24,6 +24,7 @@ type PeerTubeRequestOptions = {
24 key: string 24 key: string
25 headers: string[] 25 headers: string[]
26 } 26 }
27 timeout?: number
27 jsonResponse?: boolean 28 jsonResponse?: boolean
28} & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'> 29} & Pick<GotOptions, 'headers' | 'json' | 'method' | 'searchParams'>
29 30
@@ -92,6 +93,10 @@ const peertubeGot = got.extend({
92 path 93 path
93 }, httpSignatureOptions) 94 }, httpSignatureOptions)
94 } 95 }
96 },
97
98 (options: GotOptions) => {
99 options.timeout = REQUEST_TIMEOUT
95 } 100 }
96 ] 101 ]
97 } 102 }
@@ -182,6 +187,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
182 method: options.method, 187 method: options.method,
183 json: options.json, 188 json: options.json,
184 searchParams: options.searchParams, 189 searchParams: options.searchParams,
190 timeout: options.timeout ?? REQUEST_TIMEOUT,
185 headers, 191 headers,
186 context 192 context
187 } 193 }
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 @@
1import * as WebFinger from 'webfinger.js' 1import * as WebFinger from 'webfinger.js'
2import { isTestInstance } from '@server/helpers/core-utils' 2import { isTestInstance } from '@server/helpers/core-utils'
3import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 3import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4import { WEBSERVER } from '@server/initializers/constants' 4import { REQUEST_TIMEOUT, WEBSERVER } from '@server/initializers/constants'
5import { ActorModel } from '@server/models/actor/actor' 5import { ActorModel } from '@server/models/actor/actor'
6import { MActorFull } from '@server/types/models' 6import { MActorFull } from '@server/types/models'
7import { WebFingerData } from '@shared/models' 7import { WebFingerData } from '@shared/models'
@@ -10,7 +10,7 @@ const webfinger = new WebFinger({
10 webfist_fallback: false, 10 webfist_fallback: false,
11 tls_only: isTestInstance(), 11 tls_only: isTestInstance(),
12 uri_fallback: false, 12 uri_fallback: false,
13 request_timeout: 3000 13 request_timeout: REQUEST_TIMEOUT
14}) 14})
15 15
16async function loadActorUrlOrGetFromWebfinger (uriArg: string) { 16async 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'
3import { ActivityPubOrderedCollection } from '../../../shared/models/activitypub' 3import { ActivityPubOrderedCollection } from '../../../shared/models/activitypub'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { doJSONRequest } from '../../helpers/requests' 5import { doJSONRequest } from '../../helpers/requests'
6import { ACTIVITY_PUB, REQUEST_TIMEOUT, WEBSERVER } from '../../initializers/constants' 6import { ACTIVITY_PUB, WEBSERVER } from '../../initializers/constants'
7 7
8type HandlerFunction<T> = (items: T[]) => (Promise<any> | Bluebird<any>) 8type HandlerFunction<T> = (items: T[]) => (Promise<any> | Bluebird<any>)
9type CleanerFunction = (startedDate: Date) => (Promise<any> | Bluebird<any>) 9type CleanerFunction = (startedDate: Date) => (Promise<any> | Bluebird<any>)
@@ -13,10 +13,7 @@ async function crawlCollectionPage <T> (argUrl: string, handler: HandlerFunction
13 13
14 logger.info('Crawling ActivityPub data on %s.', url) 14 logger.info('Crawling ActivityPub data on %s.', url)
15 15
16 const options = { 16 const options = { activityPub: true }
17 activityPub: true,
18 timeout: REQUEST_TIMEOUT
19 }
20 17
21 const startDate = new Date() 18 const startDate = new Date()
22 19
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'
3import { ActivitypubHttpBroadcastPayload } from '@shared/models' 3import { ActivitypubHttpBroadcastPayload } from '@shared/models'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { doRequest } from '../../../helpers/requests' 5import { doRequest } from '../../../helpers/requests'
6import { BROADCAST_CONCURRENCY, REQUEST_TIMEOUT } from '../../../initializers/constants' 6import { BROADCAST_CONCURRENCY } from '../../../initializers/constants'
7import { ActorFollowScoreCache } from '../../files-cache' 7import { ActorFollowScoreCache } from '../../files-cache'
8import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 8import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
9 9
@@ -19,7 +19,6 @@ async function processActivityPubHttpBroadcast (job: Bull.Job) {
19 method: 'POST' as 'POST', 19 method: 'POST' as 'POST',
20 json: body, 20 json: body,
21 httpSignature: httpSignatureOptions, 21 httpSignature: httpSignatureOptions,
22 timeout: REQUEST_TIMEOUT,
23 headers: buildGlobalHeaders(body) 22 headers: buildGlobalHeaders(body)
24 } 23 }
25 24
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'
2import { ActivitypubHttpUnicastPayload } from '@shared/models' 2import { ActivitypubHttpUnicastPayload } from '@shared/models'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { doRequest } from '../../../helpers/requests' 4import { doRequest } from '../../../helpers/requests'
5import { REQUEST_TIMEOUT } from '../../../initializers/constants'
6import { ActorFollowScoreCache } from '../../files-cache' 5import { ActorFollowScoreCache } from '../../files-cache'
7import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 6import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
8 7
@@ -19,7 +18,6 @@ async function processActivityPubHttpUnicast (job: Bull.Job) {
19 method: 'POST' as 'POST', 18 method: 'POST' as 'POST',
20 json: body, 19 json: body,
21 httpSignature: httpSignatureOptions, 20 httpSignature: httpSignatureOptions,
22 timeout: REQUEST_TIMEOUT,
23 headers: buildGlobalHeaders(body) 21 headers: buildGlobalHeaders(body)
24 } 22 }
25 23