feat: Add timeout to incoming requests

This commit is contained in:
Tom Moor
2022-08-19 08:14:11 +02:00
parent f32f07cdcc
commit 8302840ab5
2 changed files with 11 additions and 0 deletions

View File

@@ -167,6 +167,15 @@ export class Environment {
@IsOptional()
public WEB_CONCURRENCY = this.toOptionalNumber(process.env.WEB_CONCURRENCY);
/**
* How long a request should be processed before giving up and returning an
* error response to the client, defaults to 10s
*/
@IsNumber()
@IsOptional()
public REQUEST_TIMEOUT =
this.toOptionalNumber(process.env.REQUEST_TIMEOUT) ?? 10 * 1000;
/**
* Base64 encoded private key if Outline is to perform SSL termination.
*/

View File

@@ -118,6 +118,8 @@ async function start(id: number, disconnect: () => void) {
});
server.listen(normalizedPortFlag || env.PORT || "3000");
server.setTimeout(env.REQUEST_TIMEOUT);
process.once("SIGTERM", shutdown);
process.once("SIGINT", shutdown);