diff --git a/.pnp.cjs b/.pnp.cjs index 07422cc41..cd41b5258 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6390,7 +6390,8 @@ const RAW_RUNTIME_STATE = ["@types/prettyjson", "npm:0.0.30"],\ ["@typescript-eslint/eslint-plugin", "virtual:fd909b174d079e30b336c4ce72c38a88c1e447767b1a8dd7655e07719a1e31b97807f0931368724fc78897ff15e6a6d00b83316c0f76d11f85111f342e08bb79#npm:6.5.0"],\ ["@typescript-eslint/parser", "virtual:fd909b174d079e30b336c4ce72c38a88c1e447767b1a8dd7655e07719a1e31b97807f0931368724fc78897ff15e6a6d00b83316c0f76d11f85111f342e08bb79#npm:6.5.0"],\ - ["axios", "npm:1.4.0"],\ + ["agentkeepalive", "npm:4.5.0"],\ + ["axios", "npm:1.6.1"],\ ["cors", "npm:2.8.5"],\ ["dotenv", "npm:16.1.3"],\ ["eslint", "npm:8.41.0"],\ @@ -8194,6 +8195,14 @@ const RAW_RUNTIME_STATE = ["humanize-ms", "npm:1.2.1"]\ ],\ "linkType": "HARD"\ + }],\ + ["npm:4.5.0", {\ + "packageLocation": "./.yarn/cache/agentkeepalive-npm-4.5.0-f237b580b2-dd210ba2a2.zip/node_modules/agentkeepalive/",\ + "packageDependencies": [\ + ["agentkeepalive", "npm:4.5.0"],\ + ["humanize-ms", "npm:1.2.1"]\ + ],\ + "linkType": "HARD"\ }]\ ]],\ ["aggregate-error", [\ @@ -8496,11 +8505,11 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["axios", [\ - ["npm:1.4.0", {\ - "packageLocation": "./.yarn/cache/axios-npm-1.4.0-4d7ce8ca3e-b987e4259e.zip/node_modules/axios/",\ + ["npm:1.6.1", {\ + "packageLocation": "./.yarn/cache/axios-npm-1.6.1-ffaff76449-fb091af3ad.zip/node_modules/axios/",\ "packageDependencies": [\ - ["axios", "npm:1.4.0"],\ - ["follow-redirects", "virtual:4d7ce8ca3e1e44d82523fba2ad95e1be18c4e9f8dec6d551377587540da3ed75bd8bd3e812280309a3b90cfdb0560f076f3552a20839f7f15665207a4fbd588a#npm:1.15.2"],\ + ["axios", "npm:1.6.1"],\ + ["follow-redirects", "virtual:ffaff76449f02e83712a7d24e03c564489516739c78ebeffb0fbcdb3893ad9a0e48504f9acfa70fe6f16debe9c8dabde3679d63bf648278ea98a5ff38cf77a9e#npm:1.15.2"],\ ["form-data", "npm:4.0.0"],\ ["proxy-from-env", "npm:1.1.0"]\ ],\ @@ -10904,10 +10913,10 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "SOFT"\ }],\ - ["virtual:4d7ce8ca3e1e44d82523fba2ad95e1be18c4e9f8dec6d551377587540da3ed75bd8bd3e812280309a3b90cfdb0560f076f3552a20839f7f15665207a4fbd588a#npm:1.15.2", {\ - "packageLocation": "./.yarn/__virtual__/follow-redirects-virtual-359bc4c55c/0/cache/follow-redirects-npm-1.15.2-1ec1dd82be-8be0d39919.zip/node_modules/follow-redirects/",\ + ["virtual:ffaff76449f02e83712a7d24e03c564489516739c78ebeffb0fbcdb3893ad9a0e48504f9acfa70fe6f16debe9c8dabde3679d63bf648278ea98a5ff38cf77a9e#npm:1.15.2", {\ + "packageLocation": "./.yarn/__virtual__/follow-redirects-virtual-c2d5794c26/0/cache/follow-redirects-npm-1.15.2-1ec1dd82be-8be0d39919.zip/node_modules/follow-redirects/",\ "packageDependencies": [\ - ["follow-redirects", "virtual:4d7ce8ca3e1e44d82523fba2ad95e1be18c4e9f8dec6d551377587540da3ed75bd8bd3e812280309a3b90cfdb0560f076f3552a20839f7f15665207a4fbd588a#npm:1.15.2"],\ + ["follow-redirects", "virtual:ffaff76449f02e83712a7d24e03c564489516739c78ebeffb0fbcdb3893ad9a0e48504f9acfa70fe6f16debe9c8dabde3679d63bf648278ea98a5ff38cf77a9e#npm:1.15.2"],\ ["@types/debug", null],\ ["debug", null]\ ],\ diff --git a/.yarn/cache/agentkeepalive-npm-4.5.0-f237b580b2-dd210ba2a2.zip b/.yarn/cache/agentkeepalive-npm-4.5.0-f237b580b2-dd210ba2a2.zip new file mode 100644 index 000000000..184528a6a Binary files /dev/null and b/.yarn/cache/agentkeepalive-npm-4.5.0-f237b580b2-dd210ba2a2.zip differ diff --git a/.yarn/cache/axios-npm-1.4.0-4d7ce8ca3e-b987e4259e.zip b/.yarn/cache/axios-npm-1.4.0-4d7ce8ca3e-b987e4259e.zip deleted file mode 100644 index 6d14839ee..000000000 Binary files a/.yarn/cache/axios-npm-1.4.0-4d7ce8ca3e-b987e4259e.zip and /dev/null differ diff --git a/.yarn/cache/axios-npm-1.6.1-ffaff76449-fb091af3ad.zip b/.yarn/cache/axios-npm-1.6.1-ffaff76449-fb091af3ad.zip new file mode 100644 index 000000000..5112fd595 Binary files /dev/null and b/.yarn/cache/axios-npm-1.6.1-ffaff76449-fb091af3ad.zip differ diff --git a/packages/api-gateway/package.json b/packages/api-gateway/package.json index 4c56aea19..f8a97381b 100644 --- a/packages/api-gateway/package.json +++ b/packages/api-gateway/package.json @@ -31,7 +31,8 @@ "@standardnotes/domain-events-infra": "workspace:*", "@standardnotes/security": "workspace:*", "@standardnotes/time": "workspace:*", - "axios": "^1.1.3", + "agentkeepalive": "^4.5.0", + "axios": "^1.6.1", "cors": "2.8.5", "dotenv": "^16.0.1", "express": "^4.18.2", diff --git a/packages/api-gateway/src/Bootstrap/Container.ts b/packages/api-gateway/src/Bootstrap/Container.ts index 81cfface5..6fec03778 100644 --- a/packages/api-gateway/src/Bootstrap/Container.ts +++ b/packages/api-gateway/src/Bootstrap/Container.ts @@ -1,7 +1,6 @@ import * as winston from 'winston' -// eslint-disable-next-line @typescript-eslint/no-var-requires -const axios = require('axios') -import { AxiosInstance } from 'axios' +import * as AgentKeepAlive from 'agentkeepalive' +import axios, { AxiosInstance } from 'axios' import Redis from 'ioredis' import { Container } from 'inversify' import { Timer, TimerInterface } from '@standardnotes/time' @@ -70,7 +69,17 @@ export class ContainerConfigLoader { container.bind(TYPES.ApiGateway_Redis).toConstantValue(redis) } - container.bind(TYPES.ApiGateway_HTTPClient).toConstantValue(axios.create()) + container.bind(TYPES.ApiGateway_HTTPClient).toConstantValue( + axios.create({ + httpAgent: new AgentKeepAlive({ + keepAlive: true, + timeout: env.get('AGENT_KEEP_ALIVE_TIMEOUT', true) ? +env.get('AGENT_KEEP_ALIVE_TIMEOUT', true) : 8_000, + freeSocketTimeout: env.get('AGENT_KEEP_ALIVE_FREE_SOCKET_TIMEOUT', true) + ? +env.get('AGENT_KEEP_ALIVE_FREE_SOCKET_TIMEOUT', true) + : 4_000, + }), + }), + ) // env vars container.bind(TYPES.ApiGateway_SYNCING_SERVER_JS_URL).toConstantValue(env.get('SYNCING_SERVER_JS_URL', true)) diff --git a/packages/auth/bin/server.ts b/packages/auth/bin/server.ts index 5c634b0de..c207844f2 100644 --- a/packages/auth/bin/server.ts +++ b/packages/auth/bin/server.ts @@ -66,6 +66,10 @@ void container.load().then((container) => { const serverInstance = server.build().listen(env.get('PORT')) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + process.on('SIGTERM', () => { logger.info('SIGTERM signal received: closing HTTP server') serverInstance.close(() => { diff --git a/packages/files/bin/server.ts b/packages/files/bin/server.ts index 4d1033e18..16c80c888 100644 --- a/packages/files/bin/server.ts +++ b/packages/files/bin/server.ts @@ -91,6 +91,10 @@ void container.load().then((container) => { const serverInstance = server.build().listen(env.get('PORT')) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + process.on('SIGTERM', () => { logger.info('SIGTERM signal received: closing HTTP server') serverInstance.close(() => { diff --git a/packages/home-server/src/Server/HomeServer.ts b/packages/home-server/src/Server/HomeServer.ts index 8dd4797e7..f5d37055a 100644 --- a/packages/home-server/src/Server/HomeServer.ts +++ b/packages/home-server/src/Server/HomeServer.ts @@ -176,6 +176,10 @@ export class HomeServer implements HomeServerInterface { const serverInstance = server.build().listen(port) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + this.serverInstance = serverInstance process.on('SIGTERM', () => { diff --git a/packages/revisions/bin/server.ts b/packages/revisions/bin/server.ts index 3e8acd389..05c54f85b 100644 --- a/packages/revisions/bin/server.ts +++ b/packages/revisions/bin/server.ts @@ -45,6 +45,10 @@ void container.load().then((container) => { const serverInstance = server.build().listen(env.get('PORT')) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + process.on('SIGTERM', () => { logger.info('SIGTERM signal received: closing HTTP server') serverInstance.close(() => { diff --git a/packages/syncing-server/bin/server.ts b/packages/syncing-server/bin/server.ts index 3bd62221a..d1fbe49cc 100644 --- a/packages/syncing-server/bin/server.ts +++ b/packages/syncing-server/bin/server.ts @@ -74,6 +74,10 @@ void container.load().then((container) => { const serverInstance = server.build().listen(env.get('PORT')) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + process.on('SIGTERM', () => { logger.info('SIGTERM signal received: closing HTTP server') serverInstance.close(() => { diff --git a/packages/websockets/bin/server.ts b/packages/websockets/bin/server.ts index dc7a932ff..8cc090482 100644 --- a/packages/websockets/bin/server.ts +++ b/packages/websockets/bin/server.ts @@ -46,6 +46,10 @@ void container.load().then((container) => { const serverInstance = server.build().listen(env.get('PORT')) + const keepAliveTimeout = env.get('KEEP_ALIVE_TIMEOUT', true) ? +env.get('KEEP_ALIVE_TIMEOUT', true) : 5000 + + serverInstance.keepAliveTimeout = keepAliveTimeout + process.on('SIGTERM', () => { logger.info('SIGTERM signal received: closing HTTP server') serverInstance.close(() => { diff --git a/yarn.lock b/yarn.lock index f664ea06f..e9fc7bb64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5249,7 +5249,8 @@ __metadata: "@types/prettyjson": "npm:^0.0.30" "@typescript-eslint/eslint-plugin": "npm:^6.5.0" "@typescript-eslint/parser": "npm:^6.5.0" - axios: "npm:^1.1.3" + agentkeepalive: "npm:^4.5.0" + axios: "npm:^1.6.1" cors: "npm:2.8.5" dotenv: "npm:^16.0.1" eslint: "npm:^8.39.0" @@ -6789,6 +6790,15 @@ __metadata: languageName: node linkType: hard +"agentkeepalive@npm:^4.5.0": + version: 4.5.0 + resolution: "agentkeepalive@npm:4.5.0" + dependencies: + humanize-ms: "npm:^1.2.1" + checksum: dd210ba2a2e2482028f027b1156789744aadbfd773a6c9dd8e4e8001930d5af82382abe19a69240307b1d8003222ce6b0542935038313434b900e351914fc15f + languageName: node + linkType: hard + "aggregate-error@npm:^3.0.0": version: 3.1.0 resolution: "aggregate-error@npm:3.1.0" @@ -7045,14 +7055,14 @@ __metadata: languageName: node linkType: hard -"axios@npm:^1.1.3": - version: 1.4.0 - resolution: "axios@npm:1.4.0" +"axios@npm:^1.6.1": + version: 1.6.1 + resolution: "axios@npm:1.6.1" dependencies: follow-redirects: "npm:^1.15.0" form-data: "npm:^4.0.0" proxy-from-env: "npm:^1.1.0" - checksum: b987e4259e5cfc93e95ee306c267a44380bbc045789a91b716e8434a75e22987344605eb4e133482fe285dd3a2e0b7e791ba26999965f04a5ecdde25f56930cb + checksum: fb091af3ad47d70fdcba5e71654b9e3c56947d93d8b2375dd0b4db63de9982adab6235aebc514488aa289c7faf103b09e8911280e6f6b1112d1604fe5f111f71 languageName: node linkType: hard