From 4c99953acd04a2405db58ae2d7656a488bcc63a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 29 Nov 2021 15:45:02 +0100 Subject: Fix redundancy timeout --- server/helpers/requests.ts | 7 ++++--- server/initializers/constants.ts | 9 +++++++-- server/lib/activitypub/actors/webfinger.ts | 4 ++-- server/lib/hls.ts | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index fc77ebd35..327610558 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -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, diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index b65741bbd..b8633e83e 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -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, diff --git a/server/lib/activitypub/actors/webfinger.ts b/server/lib/activitypub/actors/webfinger.ts index 5532f05bd..b20a724da 100644 --- a/server/lib/activitypub/actors/webfinger.ts +++ b/server/lib/activitypub/actors/webfinger.ts @@ -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) { diff --git a/server/lib/hls.ts b/server/lib/hls.ts index d969549b8..3331e6272 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -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) -- cgit v1.2.3