]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix redundancy timeout
authorChocobozzz <me@florianbigard.com>
Mon, 29 Nov 2021 14:45:02 +0000 (15:45 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 29 Nov 2021 14:45:02 +0000 (15:45 +0100)
server/helpers/requests.ts
server/initializers/constants.ts
server/lib/activitypub/actors/webfinger.ts
server/lib/hls.ts

index fc77ebd357f5f1d8d8f57f2a42f90a810a56dc55..327610558008ef439bf7e5b76abeba2a20415ccb 100644 (file)
@@ -3,7 +3,7 @@ import got, { CancelableRequest, NormalizedOptions, Options as GotOptions, Reque
 import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent'
 import { join } from 'path'
 import { CONFIG } from '../initializers/config'
-import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUT, WEBSERVER } from '../initializers/constants'
+import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUTS, WEBSERVER } from '../initializers/constants'
 import { pipelinePromise } from './core-utils'
 import { processImage } from './image-utils'
 import { logger, loggerTagsFactory } from './logger'
@@ -20,6 +20,7 @@ export interface PeerTubeRequestError extends Error {
 }
 
 type PeerTubeRequestOptions = {
+  timeout?: number
   activityPub?: boolean
   bodyKBLimit?: number // 1MB
   httpSignature?: {
@@ -129,7 +130,7 @@ async function doRequestAndSaveToFile (
   destPath: string,
   options: PeerTubeRequestOptions = {}
 ) {
-  const gotOptions = buildGotOptions(options)
+  const gotOptions = buildGotOptions({ ...options, timeout: options.timeout ?? REQUEST_TIMEOUTS.FILE })
 
   const outFile = createWriteStream(destPath)
 
@@ -235,7 +236,7 @@ function buildGotOptions (options: PeerTubeRequestOptions) {
   return {
     method: options.method,
     dnsCache: true,
-    timeout: REQUEST_TIMEOUT,
+    timeout: options.timeout ?? REQUEST_TIMEOUTS.DEFAULT,
     json: options.json,
     searchParams: options.searchParams,
     retry: 2,
index b65741bbd29457de648a082c64e812245b77f4c9..b8633e83e1bddcadad24f71a685f9159f9fae980 100644 (file)
@@ -202,7 +202,12 @@ const JOB_PRIORITY = {
 const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
 const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job
 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
-const REQUEST_TIMEOUT = 7000 // 7 seconds
+const REQUEST_TIMEOUTS = {
+  DEFAULT: 7000, // 7 seconds
+  FILE: 30000, // 30 seconds
+  REDUNDANCY: JOB_TTL['video-redundancy']
+}
+
 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
 
@@ -896,7 +901,7 @@ export {
   FFMPEG_NICE,
   ABUSE_STATES,
   LRU_CACHE,
-  REQUEST_TIMEOUT,
+  REQUEST_TIMEOUTS,
   USER_PASSWORD_RESET_LIFETIME,
   USER_PASSWORD_CREATE_LIFETIME,
   MEMOIZE_TTL,
index 5532f05bd8ba3d6392669a46cfa41f408ba71b88..b20a724dad3e85fa2edc59c0df90afb03325217c 100644 (file)
@@ -1,7 +1,7 @@
 import WebFinger from 'webfinger.js'
 import { isProdInstance } from '@server/helpers/core-utils'
 import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
-import { REQUEST_TIMEOUT, WEBSERVER } from '@server/initializers/constants'
+import { REQUEST_TIMEOUTS, 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: isProdInstance(),
   uri_fallback: false,
-  request_timeout: REQUEST_TIMEOUT
+  request_timeout: REQUEST_TIMEOUTS.DEFAULT
 })
 
 async function loadActorUrlOrGetFromWebfinger (uriArg: string) {
index d969549b86d3909df2eaba65a376f9d966fbf203..3331e6272237ee0984f490db94f2fd673a252081 100644 (file)
@@ -130,7 +130,7 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string,
       for (const fileUrl of fileUrls) {
         const destPath = join(tmpDirectory, basename(fileUrl))
 
-        await doRequestAndSaveToFile(fileUrl, destPath, { bodyKBLimit: remainingBodyKBLimit })
+        await doRequestAndSaveToFile(fileUrl, destPath, { bodyKBLimit: remainingBodyKBLimit, timeout: REQUEST_TIMEOUTS.FILE })
 
         const { size } = await stat(destPath)
         remainingBodyKBLimit -= (size / 1000)