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:
parent
b4df49b87f
commit
da23ad1d09
8 changed files with 18 additions and 24 deletions
|
@ -15,6 +15,10 @@ secrets:
|
||||||
# Generate one using `openssl rand -hex 32`
|
# Generate one using `openssl rand -hex 32`
|
||||||
peertube: ''
|
peertube: ''
|
||||||
|
|
||||||
|
# How long PeerTube should wait to receive the entire request
|
||||||
|
http_timeouts:
|
||||||
|
request: '5 minutes'
|
||||||
|
|
||||||
rates_limit:
|
rates_limit:
|
||||||
api:
|
api:
|
||||||
# 50 attempts in 10 seconds
|
# 50 attempts in 10 seconds
|
||||||
|
@ -61,7 +65,6 @@ rates_limit:
|
||||||
window: 5 seconds
|
window: 5 seconds
|
||||||
max: 5
|
max: 5
|
||||||
|
|
||||||
|
|
||||||
oauth2:
|
oauth2:
|
||||||
token_lifetime:
|
token_lifetime:
|
||||||
access_token: '1 day'
|
access_token: '1 day'
|
||||||
|
@ -339,6 +342,9 @@ security:
|
||||||
powered_by_header:
|
powered_by_header:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
http_server:
|
||||||
|
request_timeout: '5 minutes'
|
||||||
|
|
||||||
tracker:
|
tracker:
|
||||||
# If you disable the tracker, you disable the P2P on your PeerTube instance
|
# If you disable the tracker, you disable the P2P on your PeerTube instance
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
@ -13,6 +13,10 @@ secrets:
|
||||||
# Generate one using `openssl rand -hex 32`
|
# Generate one using `openssl rand -hex 32`
|
||||||
peertube: ''
|
peertube: ''
|
||||||
|
|
||||||
|
# How long PeerTube should wait to receive the entire request
|
||||||
|
http_timeouts:
|
||||||
|
request: '5 minutes'
|
||||||
|
|
||||||
rates_limit:
|
rates_limit:
|
||||||
api:
|
api:
|
||||||
# 50 attempts in 10 seconds
|
# 50 attempts in 10 seconds
|
||||||
|
@ -59,7 +63,6 @@ rates_limit:
|
||||||
window: 5 seconds
|
window: 5 seconds
|
||||||
max: 5
|
max: 5
|
||||||
|
|
||||||
|
|
||||||
oauth2:
|
oauth2:
|
||||||
token_lifetime:
|
token_lifetime:
|
||||||
access_token: '1 day'
|
access_token: '1 day'
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { setupUploadResumableRoutes, uploadx } from '@server/lib/uploadx.js'
|
||||||
import { buildNextVideoState } from '@server/lib/video-state.js'
|
import { buildNextVideoState } from '@server/lib/video-state.js'
|
||||||
import { openapiOperationDoc } from '@server/middlewares/doc.js'
|
import { openapiOperationDoc } from '@server/middlewares/doc.js'
|
||||||
import express from 'express'
|
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 { createReqFiles } from '../../../helpers/express-utils.js'
|
||||||
import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
|
import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
|
||||||
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
|
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
|
||||||
|
@ -17,7 +17,6 @@ import {
|
||||||
asyncMiddleware,
|
asyncMiddleware,
|
||||||
asyncRetryTransactionMiddleware,
|
asyncRetryTransactionMiddleware,
|
||||||
authenticate,
|
authenticate,
|
||||||
setReqTimeout,
|
|
||||||
videosAddLegacyValidator,
|
videosAddLegacyValidator,
|
||||||
videosAddResumableInitValidator,
|
videosAddResumableInitValidator,
|
||||||
videosAddResumableValidator
|
videosAddResumableValidator
|
||||||
|
@ -42,7 +41,6 @@ uploadRouter.post(
|
||||||
'/upload',
|
'/upload',
|
||||||
openapiOperationDoc({ operationId: 'uploadLegacy' }),
|
openapiOperationDoc({ operationId: 'uploadLegacy' }),
|
||||||
authenticate,
|
authenticate,
|
||||||
setReqTimeout(1000 * 60 * 10), // Uploading the video could be long
|
|
||||||
reqVideoFileAdd,
|
reqVideoFileAdd,
|
||||||
asyncMiddleware(videosAddLegacyValidator),
|
asyncMiddleware(videosAddLegacyValidator),
|
||||||
asyncRetryTransactionMiddleware(addVideoLegacy)
|
asyncRetryTransactionMiddleware(addVideoLegacy)
|
||||||
|
|
|
@ -14,6 +14,7 @@ export function checkMissedConfig () {
|
||||||
'webserver.hostname',
|
'webserver.hostname',
|
||||||
'webserver.port',
|
'webserver.port',
|
||||||
'secrets.peertube',
|
'secrets.peertube',
|
||||||
|
'http_timeouts.request',
|
||||||
'trust_proxy',
|
'trust_proxy',
|
||||||
'oauth2.token_lifetime.access_token',
|
'oauth2.token_lifetime.access_token',
|
||||||
'oauth2.token_lifetime.refresh_token',
|
'oauth2.token_lifetime.refresh_token',
|
||||||
|
|
|
@ -29,6 +29,9 @@ const CONFIG = {
|
||||||
SECRETS: {
|
SECRETS: {
|
||||||
PEERTUBE: config.get<string>('secrets.peertube')
|
PEERTUBE: config.get<string>('secrets.peertube')
|
||||||
},
|
},
|
||||||
|
HTTP_TIMEOUTS: {
|
||||||
|
REQUEST: parseDurationToMs(config.get<number>('http_timeouts.request'))
|
||||||
|
},
|
||||||
DATABASE: {
|
DATABASE: {
|
||||||
DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
|
DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
|
||||||
HOSTNAME: config.get<string>('database.hostname'),
|
HOSTNAME: config.get<string>('database.hostname'),
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,6 +10,5 @@ export * from './sort.js'
|
||||||
export * from './user-right.js'
|
export * from './user-right.js'
|
||||||
export * from './dnt.js'
|
export * from './dnt.js'
|
||||||
export * from './error.js'
|
export * from './error.js'
|
||||||
export * from './express.js'
|
|
||||||
export * from './doc.js'
|
export * from './doc.js'
|
||||||
export * from './csp.js'
|
export * from './csp.js'
|
||||||
|
|
|
@ -283,6 +283,8 @@ app.use((err, req, res: express.Response, _next) => {
|
||||||
|
|
||||||
const { server, trackerServer } = createWebsocketTrackerServer(app)
|
const { server, trackerServer } = createWebsocketTrackerServer(app)
|
||||||
|
|
||||||
|
server.requestTimeout = CONFIG.HTTP_TIMEOUTS.REQUEST
|
||||||
|
|
||||||
// ----------- Run -----------
|
// ----------- Run -----------
|
||||||
|
|
||||||
async function startApplication () {
|
async function startApplication () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue