Skip to content

Commit

Permalink
tunnel server: fix keepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Mar 13, 2024
1 parent bb5bfd5 commit 9524902
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions tunnel-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@fastify/cors": "^8.3.0",
"@fastify/request-context": "^5.0.0",
"@sindresorhus/fnv1a": "^3.0.0",
"agentkeepalive": "^4.5.0",
"content-type": "^1.0.5",
"cookies": "^0.8.0",
"fastify": "^4.22.2",
Expand Down
10 changes: 9 additions & 1 deletion tunnel-server/src/proxy/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import httpProxy from 'http-proxy'
import { IncomingMessage } from 'http'
import Agent from 'agentkeepalive'
import net from 'net'
import type { Logger } from 'pino'
import { inspect } from 'util'
Expand Down Expand Up @@ -43,7 +44,14 @@ export const proxy = ({
authFactory: (client: { publicKey: KeyObject; publicKeyThumbprint: string }) => Authenticator
loginUrl: ({ env, returnPath }: { env: string; returnPath?: string }) => string
}) => {
const theProxy = httpProxy.createProxyServer({ xfwd: true })
const agent = new Agent({
maxSockets: 100,
keepAlive: true,
maxFreeSockets: 10,
timeout: 60000,
})

const theProxy = httpProxy.createProxyServer({ xfwd: true, agent })
const injectionHandlers = proxyInjectionHandlers({ log })
theProxy.on('proxyRes', injectionHandlers.proxyResHandler)
theProxy.on('proxyReq', injectionHandlers.proxyReqHandler)
Expand Down
16 changes: 15 additions & 1 deletion tunnel-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,13 @@ acorn@^8.9.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==

agentkeepalive@^4.5.0:
version "4.5.0"
resolved "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz#2673ad1389b3c418c5a20c5d7364f93ca04be923"
integrity sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==
dependencies:
humanize-ms "^1.2.1"

ajv-formats@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520"
Expand Down Expand Up @@ -2299,6 +2306,13 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

humanize-ms@^1.2.1:
version "1.2.1"
resolved "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed"
integrity sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==
dependencies:
ms "^2.0.0"

iconv-lite@^0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
Expand Down Expand Up @@ -3052,7 +3066,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@^2.1.1:
ms@^2.0.0, ms@^2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
Expand Down

0 comments on commit 9524902

Please sign in to comment.