1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 01:39:37 +02:00

Add ability for admin to configure request timeout

AFAIK we can't set a specific timeout on a specific route/request, so
the admin must set it globally
This commit is contained in:
Chocobozzz 2025-08-11 16:55:37 +02:00
parent b4df49b87f
commit da23ad1d09
No known key found for this signature in database
GPG key ID: 583A612D890159BE
8 changed files with 18 additions and 24 deletions

View file

@ -15,6 +15,10 @@ secrets:
# Generate one using `openssl rand -hex 32`
peertube: ''
# How long PeerTube should wait to receive the entire request
http_timeouts:
request: '5 minutes'
rates_limit:
api:
# 50 attempts in 10 seconds
@ -61,7 +65,6 @@ rates_limit:
window: 5 seconds
max: 5
oauth2:
token_lifetime:
access_token: '1 day'
@ -339,6 +342,9 @@ security:
powered_by_header:
enabled: true
http_server:
request_timeout: '5 minutes'
tracker:
# If you disable the tracker, you disable the P2P on your PeerTube instance
enabled: true

View file

@ -13,6 +13,10 @@ secrets:
# Generate one using `openssl rand -hex 32`
peertube: ''
# How long PeerTube should wait to receive the entire request
http_timeouts:
request: '5 minutes'
rates_limit:
api:
# 50 attempts in 10 seconds
@ -59,7 +63,6 @@ rates_limit:
window: 5 seconds
max: 5
oauth2:
token_lifetime:
access_token: '1 day'

View file

@ -8,7 +8,7 @@ import { setupUploadResumableRoutes, uploadx } from '@server/lib/uploadx.js'
import { buildNextVideoState } from '@server/lib/video-state.js'
import { openapiOperationDoc } from '@server/middlewares/doc.js'
import express from 'express'
import { VideoAuditView, auditLoggerFactory, getAuditIdFromRes } from '../../../helpers/audit-logger.js'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger.js'
import { createReqFiles } from '../../../helpers/express-utils.js'
import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
@ -17,7 +17,6 @@ import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
authenticate,
setReqTimeout,
videosAddLegacyValidator,
videosAddResumableInitValidator,
videosAddResumableValidator
@ -42,7 +41,6 @@ uploadRouter.post(
'/upload',
openapiOperationDoc({ operationId: 'uploadLegacy' }),
authenticate,
setReqTimeout(1000 * 60 * 10), // Uploading the video could be long
reqVideoFileAdd,
asyncMiddleware(videosAddLegacyValidator),
asyncRetryTransactionMiddleware(addVideoLegacy)

View file

@ -14,6 +14,7 @@ export function checkMissedConfig () {
'webserver.hostname',
'webserver.port',
'secrets.peertube',
'http_timeouts.request',
'trust_proxy',
'oauth2.token_lifetime.access_token',
'oauth2.token_lifetime.refresh_token',

View file

@ -29,6 +29,9 @@ const CONFIG = {
SECRETS: {
PEERTUBE: config.get<string>('secrets.peertube')
},
HTTP_TIMEOUTS: {
REQUEST: parseDurationToMs(config.get<number>('http_timeouts.request'))
},
DATABASE: {
DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
HOSTNAME: config.get<string>('database.hostname'),

View file

@ -1,18 +0,0 @@
import { HttpStatusCode } from '@peertube/peertube-models'
import { logger } from '@server/helpers/logger.js'
import express from 'express'
export function setReqTimeout (timeoutMs: number) {
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
req.setTimeout(timeoutMs, () => {
logger.error('Express request timeout in ' + req.originalUrl)
return res.fail({
status: HttpStatusCode.REQUEST_TIMEOUT_408,
message: 'Request has timed out.'
})
})
next()
}
}

View file

@ -10,6 +10,5 @@ export * from './sort.js'
export * from './user-right.js'
export * from './dnt.js'
export * from './error.js'
export * from './express.js'
export * from './doc.js'
export * from './csp.js'

View file

@ -283,6 +283,8 @@ app.use((err, req, res: express.Response, _next) => {
const { server, trackerServer } = createWebsocketTrackerServer(app)
server.requestTimeout = CONFIG.HTTP_TIMEOUTS.REQUEST
// ----------- Run -----------
async function startApplication () {