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`
|
||||
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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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 './dnt.js'
|
||||
export * from './error.js'
|
||||
export * from './express.js'
|
||||
export * from './doc.js'
|
||||
export * from './csp.js'
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue