]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Use a global request timeout
authorChocobozzz <me@florianbigard.com>
Mon, 14 Jun 2021 16:06:58 +0000 (18:06 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 15 Jun 2021 06:21:31 +0000 (08:21 +0200)
server/helpers/requests.ts
server/lib/activitypub/actors/webfinger.ts
server/lib/activitypub/crawl.ts
server/lib/job-queue/handlers/activitypub-http-broadcast.ts
server/lib/job-queue/handlers/activitypub-http-unicast.ts

index fd2a56f30c717e6ce892b1fd90deca6af228a327..d3c83d26e29f25dc78ac884e3cda2c3a2003e17e 100644 (file)
@@ -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
   }
index cf8eddfc7ddd8111d2513f20a5d92c31d543dc29..723fca5860ecec8d191d42ec2bd9c70ac33fcf82 100644 (file)
@@ -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) {
index 278abf7de0b3a9637b380521dd9f78158535686f..cd117f5712896e81ce374722723353a0e07ebbc8 100644 (file)
@@ -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()
 
index c69ff9e83fd2dcf5a920e51c47ad55a7d15ae66e..d4b328635a528a50d96bbba143d6da5db50360eb 100644 (file)
@@ -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)
   }
 
index 585dad671e04f7c5074646920b197a8ac6945836..9e561c6b757b1b7c4f0564d30691f175df188fa5 100644 (file)
@@ -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)
   }