From 940fa051eb2b88a925ac64a62f8c6d97e37b83ec Mon Sep 17 00:00:00 2001 From: John Shearar Date: Fri, 23 Jan 2026 14:12:04 -0700 Subject: [PATCH 01/43] WIP: track multiple sockets for mongo driver's connection pool --- src/mongoPatch.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index c647cf0..b9e778c 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -13,17 +13,23 @@ interface Config { * @param config - The configuration for the proxy */ export function useProxyForMongo(config: Config) { - let socket: tls.TLSSocket; + const sockets: tls.TLSSocket[] = []; socks.SocksClient.createConnection = async (options, callback) => { const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); - return new Promise(async (resolve, reject) => { - socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); - resolve({ - socket, - }); - }); + const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); + sockets.push(socket) + return { + socket + }; }; return { - close: () => socket?.end(), + close: async () => { + for (const socket of sockets) { + await new Promise((resolve, reject) => { + socket.once('close', () => resolve); + socket.end() + }) + } + }, }; } From 992b6c8c4f66d98f9414c8d104a19b0605c672fe Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Sat, 24 Jan 2026 09:27:04 +0200 Subject: [PATCH 02/43] nvmrc file in ci --- .github/workflows/dev-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-package.yml b/.github/workflows/dev-package.yml index e285f38..ac04ccf 100644 --- a/.github/workflows/dev-package.yml +++ b/.github/workflows/dev-package.yml @@ -25,7 +25,7 @@ jobs: - name: Setup NodeJS uses: actions/setup-node@v4 with: - node-version: 22.16 + node-version-file: '.nvmrc' - uses: pnpm/action-setup@v4 name: Install pnpm From ede8f21222f4b0225277d91a2306c44df7bd48c8 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 08:49:55 +0200 Subject: [PATCH 03/43] git workflows --- .github/workflows/dev-package.yml | 52 ---------------------- .github/workflows/publish.yml | 68 ----------------------------- .github/workflows/release.yml | 71 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/dev-package.yml delete mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/dev-package.yml b/.github/workflows/dev-package.yml deleted file mode 100644 index ac04ccf..0000000 --- a/.github/workflows/dev-package.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Dev Packages - -on: workflow_dispatch -env: - SECRETS: ${{ toJSON(secrets) }} - GITHUB_TOKEN: ${{ secrets.SHARED_GH_TOKEN }} - -jobs: - build: - name: Create Development Packages - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{github.event.pull_request.head.sha}} - fetch-depth: 0 - - - uses: actions/checkout@v4 - with: - repository: journeyapps-platform/ci-actions - token: ${{ secrets.SHARED_GH_TOKEN }} - path: .github/ci - ref: v1 - - - name: Setup NodeJS - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - - uses: pnpm/action-setup@v4 - name: Install pnpm - with: - version: 10 - - - - name: Install Dependencies - uses: ./.github/ci/actions/npm-install - with: - client: pnpm - - - name: Has changesets - uses: bluwy/detect-changesets-action@v1 - id: detect - - - name: Build - run: pnpm build - - - name: Publish dev packages. - if: ${{ success() }} - uses: ./.github/ci/actions/pnpm-publish - with: - dev: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index a109c56..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Build and Publish -on: - workflow_dispatch: - push: - branches: - - "**" - tags-ignore: - - "**" - -env: - SECRETS: ${{ toJSON(secrets) }} - GITHUB_TOKEN: ${{ secrets.SHARED_GH_TOKEN }} - -jobs: - build: - name: Publish Packages - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{github.event.pull_request.head.sha}} - fetch-depth: 0 - - - uses: actions/checkout@v4 - with: - repository: journeyapps-platform/ci-actions - token: ${{ secrets.SHARED_GH_TOKEN }} - path: .github/ci - ref: v1 - - - name: Setup NodeJS - uses: actions/setup-node@v4 - with: - node-version: 22.16 - - - uses: pnpm/action-setup@v4 - name: Install pnpm - with: - version: 10 - - - name: Install Dependencies - uses: ./.github/ci/actions/npm-install - with: - client: pnpm - - - - name: Has changesets - uses: bluwy/detect-changesets-action@v1 - id: detect - - - name: Build - run: pnpm build - - - name: Create Release Pull Request or Publish to npm - if: ${{ github.ref == 'refs/heads/master' && steps.detect.outputs.has-changesets == 'true' }} - id: changesets - uses: changesets/action@v1.4.1 - with: - version: pnpm ci:version - commit: "chore: update versions" - title: "[Chore] update versions" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish production packages. - if: ${{ github.ref == 'refs/heads/master' && steps.detect.outputs.has-changesets == 'false' && success() }} - run: | - pnpm ci:publish \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..50f6521 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,71 @@ +name: Release +on: + push: + branches: [main] + workflow_dispatch: # For dev publishing + +concurrency: ${{ github.workflow }}-${{ github.ref }} +permissions: + id-token: write # Required for OIDC / trusted publishing + contents: write # Required for changesets pushing commits + pull-requests: write # Required for changesets creating PRs + +jobs: + release: + name: Publish Packages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{github.event.pull_request.head.sha}} + fetch-depth: 0 + + - uses: actions/checkout@v4 + with: + repository: journeyapps-platform/ci-actions + token: ${{ secrets.SHARED_GH_TOKEN }} + path: .github/ci + ref: v1 + + - name: Enable Corepack + run: corepack enable + + + - name: Setup NodeJS + uses: actions/setup-node@v6 + with: + node-version-file: ".nvmrc" + cache: pnpm + + + - name: Update npm + run: | + npm install -g npm@latest + npm --version + + - name: Install dependencies + run: pnpm install + + + - name: Has changesets + uses: bluwy/detect-changesets-action@v1 + id: detect + + - name: Build + run: pnpm build + + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 + if: ${{ github.event_name == 'push' }} + with: + version: pnpm changeset:version + publish: ci:publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Dev publish + if: ${{ github.event_name == 'workflow_dispatch' }} + run: pnpm ci:version + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 94c3c5eea18d45fa237a7a86037431dfb87ade02 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 08:55:07 +0200 Subject: [PATCH 04/43] version bump --- .changeset/vast-memes-repair.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/vast-memes-repair.md diff --git a/.changeset/vast-memes-repair.md b/.changeset/vast-memes-repair.md new file mode 100644 index 0000000..0d3cfdc --- /dev/null +++ b/.changeset/vast-memes-repair.md @@ -0,0 +1,5 @@ +--- +'@journeyapps/https-proxy-socket': patch +--- + +Mongo hack fix, multi socket closure From 1513c917281417c0960ec1515409fc59437e76cd Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 08:58:12 +0200 Subject: [PATCH 05/43] branch --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 50f6521..9907ee9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,7 @@ name: Release on: push: - branches: [main] + branches: [master] workflow_dispatch: # For dev publishing concurrency: ${{ github.workflow }}-${{ github.ref }} From 07c3e46c40b81406365773f4826c9e77b778883b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 09:04:38 +0200 Subject: [PATCH 06/43] workflow --- .github/workflows/release.yml | 6 +++++- .github/workflows/{test.yaml => test.yml} | 0 2 files changed, 5 insertions(+), 1 deletion(-) rename .github/workflows/{test.yaml => test.yml} (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9907ee9..b4fc2b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,10 @@ permissions: contents: write # Required for changesets pushing commits pull-requests: write # Required for changesets creating PRs +env: + SECRETS: ${{ toJSON(secrets) }} + GITHUB_TOKEN: ${{ secrets.SHARED_GH_TOKEN }} + jobs: release: name: Publish Packages @@ -64,7 +68,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Dev publish + - name: Dev packages if: ${{ github.event_name == 'workflow_dispatch' }} run: pnpm ci:version env: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/test.yaml rename to .github/workflows/test.yml From 43406ba3a5d5fa4b070796a899d418279e81b145 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 09:15:48 +0200 Subject: [PATCH 07/43] workflow --- .github/workflows/release.yml | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4fc2b6..1f77c0d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,10 @@ name: Release + + on: push: branches: [master] - workflow_dispatch: # For dev publishing + workflow_dispatch: concurrency: ${{ github.workflow }}-${{ github.ref }} permissions: @@ -10,26 +12,13 @@ permissions: contents: write # Required for changesets pushing commits pull-requests: write # Required for changesets creating PRs -env: - SECRETS: ${{ toJSON(secrets) }} - GITHUB_TOKEN: ${{ secrets.SHARED_GH_TOKEN }} - jobs: - release: - name: Publish Packages + realeas: + name: Release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - ref: ${{github.event.pull_request.head.sha}} - fetch-depth: 0 - - - uses: actions/checkout@v4 - with: - repository: journeyapps-platform/ci-actions - token: ${{ secrets.SHARED_GH_TOKEN }} - path: .github/ci - ref: v1 + - name: Checkout Repo + uses: actions/checkout@v5 - name: Enable Corepack run: corepack enable @@ -51,10 +40,6 @@ jobs: run: pnpm install - - name: Has changesets - uses: bluwy/detect-changesets-action@v1 - id: detect - - name: Build run: pnpm build From 2884d8c8732cc2b6f58a3484a69f99230cbaa79b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 09:18:29 +0200 Subject: [PATCH 08/43] workflow --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1f77c0d..320a045 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,13 +48,15 @@ jobs: uses: changesets/action@v1 if: ${{ github.event_name == 'push' }} with: + publish: pnpm ci:publish version: pnpm changeset:version - publish: ci:publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Dev packages if: ${{ github.event_name == 'workflow_dispatch' }} - run: pnpm ci:version + run: | + pnpm changeset version --no-git-tag --snapshot dev + pnpm changeset publish --tag dev env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From c1cee880990fb135044d43f19fcd3d3f5b55b4c5 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 09:55:15 +0200 Subject: [PATCH 09/43] workflow --- .github/workflows/release.yml | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 320a045..3f689a4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,20 +1,24 @@ name: Release - on: push: branches: [master] - workflow_dispatch: + workflow_dispatch: # For dev publishing concurrency: ${{ github.workflow }}-${{ github.ref }} + permissions: id-token: write # Required for OIDC / trusted publishing contents: write # Required for changesets pushing commits pull-requests: write # Required for changesets creating PRs +env: + SECRETS: ${{ toJSON(secrets) }} + GITHUB_TOKEN: ${{ secrets.SHARED_GH_TOKEN }} + jobs: - realeas: - name: Release + build: + name: Publish Packages runs-on: ubuntu-latest steps: - name: Checkout Repo @@ -23,7 +27,6 @@ jobs: - name: Enable Corepack run: corepack enable - - name: Setup NodeJS uses: actions/setup-node@v6 with: @@ -37,23 +40,22 @@ jobs: npm --version - name: Install dependencies - run: pnpm install - + run: pnpm install --no-frozen-lockfile - name: Build run: pnpm build - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@v1 - if: ${{ github.event_name == 'push' }} - with: - publish: pnpm ci:publish - version: pnpm changeset:version - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Create Release Pull Request or Publish to npm + # id: changesets + # uses: changesets/action@v1 + # if: ${{ github.event_name == 'push' }} + # with: + # version: pnpm ci:version + # publish: pnpm ci:publish + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Dev packages + - name: Dev publish if: ${{ github.event_name == 'workflow_dispatch' }} run: | pnpm changeset version --no-git-tag --snapshot dev From ace8ee18dfa555fef739f10f9292bfff3e19a091 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 10:05:18 +0200 Subject: [PATCH 10/43] Check soccket length --- src/mongoPatch.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index b9e778c..be2bfd5 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -24,6 +24,7 @@ export function useProxyForMongo(config: Config) { }; return { close: async () => { + console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { socket.once('close', () => resolve); From 7eb36d5179d5bb302cc2ccffc1712ee3440927e3 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 11:04:15 +0200 Subject: [PATCH 11/43] test --- src/mongoPatch.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index be2bfd5..13c31c4 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -17,9 +17,9 @@ export function useProxyForMongo(config: Config) { socks.SocksClient.createConnection = async (options, callback) => { const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); - sockets.push(socket) + sockets.push(socket); return { - socket + socket, }; }; return { @@ -27,9 +27,10 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { + socket.setKeepAlive(false); socket.once('close', () => resolve); - socket.end() - }) + socket.end(); + }); } }, }; From 2ab9a428aba08bdaea0ce44f0b216a83386ed151 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 11:40:23 +0200 Subject: [PATCH 12/43] destroy socket --- src/mongoPatch.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 13c31c4..c4861a7 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -27,9 +27,11 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.setKeepAlive(false); socket.once('close', () => resolve); socket.end(); + setTimeout(() => { + resolve(socket.destroy()); + }, 3000); }); } }, From bc164d372fa05b4a28aea322fb16eefde4d9adaa Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 11:48:12 +0200 Subject: [PATCH 13/43] urgh --- src/mongoPatch.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index c4861a7..6ba1264 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -27,11 +27,11 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.once('close', () => resolve); + socket.on('close', () => { + console.log('Closed socket to', socket.remoteAddress, socket.remotePort); + resolve(null); + }); socket.end(); - setTimeout(() => { - resolve(socket.destroy()); - }, 3000); }); } }, From 45349d63314b3bfe26873adbecaf0f53640fa0f4 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 11:53:30 +0200 Subject: [PATCH 14/43] test --- src/mongoPatch.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 6ba1264..e824558 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -27,11 +27,12 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.on('close', () => { - console.log('Closed socket to', socket.remoteAddress, socket.remotePort); + socket.once('close', () => { resolve(null); }); - socket.end(); + socket.end(()=>{ + console.log('Ended socket to', socket.remoteAddress, socket.remotePort); + }) }); } }, From c9ac7af869b7b13e5553089dd0c6f62264eb2dfb Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:00:06 +0200 Subject: [PATCH 15/43] test --- src/mongoPatch.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index e824558..c01c2bf 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -28,11 +28,10 @@ export function useProxyForMongo(config: Config) { for (const socket of sockets) { await new Promise((resolve, reject) => { socket.once('close', () => { - resolve(null); + console.log({ socket }); + resolve(socket); }); - socket.end(()=>{ - console.log('Ended socket to', socket.remoteAddress, socket.remotePort); - }) + socket.end(); }); } }, From 079f28e04945516786e45db47321485760a75d4a Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:08:58 +0200 Subject: [PATCH 16/43] test --- src/mongoPatch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index c01c2bf..5b8d434 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -27,8 +27,8 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.once('close', () => { - console.log({ socket }); + socket.on('close', () => { + socket.destroy(); resolve(socket); }); socket.end(); From f3f5d695dff8330e283921e805f606b0a9c7a809 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:21:18 +0200 Subject: [PATCH 17/43] test --- src/mongoPatch.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 5b8d434..fd20f8c 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -14,8 +14,8 @@ interface Config { */ export function useProxyForMongo(config: Config) { const sockets: tls.TLSSocket[] = []; + const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); socks.SocksClient.createConnection = async (options, callback) => { - const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); sockets.push(socket); return { @@ -27,10 +27,7 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.on('close', () => { - socket.destroy(); - resolve(socket); - }); + socket.on('close', () => resolve); socket.end(); }); } From 0c57f749e697405140b3bc0f0658bdf28175cb04 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:28:37 +0200 Subject: [PATCH 18/43] test --- src/mongoPatch.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index fd20f8c..9ee5629 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -27,10 +27,15 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.on('close', () => resolve); + socket.on('close', () => { + console.log(`Socket ${socket.address()}: `, socket.closed); + console.log('Socket is paused: ', socket.isPaused()); + resolve(true); + }); socket.end(); }); } + return Promise.resolve(true); }, }; } From e655ab68d310b9189da06d9a79bc0c553662722a Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:33:32 +0200 Subject: [PATCH 19/43] test --- src/mongoPatch.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 9ee5629..d19aea8 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -28,14 +28,13 @@ export function useProxyForMongo(config: Config) { for (const socket of sockets) { await new Promise((resolve, reject) => { socket.on('close', () => { - console.log(`Socket ${socket.address()}: `, socket.closed); + console.log(`Socket ${socket.remoteAddress}: `, socket.closed); console.log('Socket is paused: ', socket.isPaused()); resolve(true); }); socket.end(); }); } - return Promise.resolve(true); }, }; } From 99000873b66b67b35cac72fd04250a552aaed764 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:48:21 +0200 Subject: [PATCH 20/43] test --- src/mongoPatch.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index d19aea8..e814d2d 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -14,8 +14,8 @@ interface Config { */ export function useProxyForMongo(config: Config) { const sockets: tls.TLSSocket[] = []; - const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); socks.SocksClient.createConnection = async (options, callback) => { + const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); sockets.push(socket); return { @@ -28,8 +28,7 @@ export function useProxyForMongo(config: Config) { for (const socket of sockets) { await new Promise((resolve, reject) => { socket.on('close', () => { - console.log(`Socket ${socket.remoteAddress}: `, socket.closed); - console.log('Socket is paused: ', socket.isPaused()); + socket.unref(); resolve(true); }); socket.end(); From 4491c9bf059f24fc6f3f319709a0a6ac78eb516e Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:52:47 +0200 Subject: [PATCH 21/43] test --- src/mongoPatch.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index e814d2d..6be708e 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -17,6 +17,7 @@ export function useProxyForMongo(config: Config) { socks.SocksClient.createConnection = async (options, callback) => { const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); + socket.unref() sockets.push(socket); return { socket, @@ -27,10 +28,7 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.on('close', () => { - socket.unref(); - resolve(true); - }); + socket.on('close', () => resolve); socket.end(); }); } From dfab84dbb377dc6af90c788b6af96218d1a6d0c3 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 12:53:39 +0200 Subject: [PATCH 22/43] test --- src/mongoPatch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 6be708e..419d3d1 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -17,7 +17,7 @@ export function useProxyForMongo(config: Config) { socks.SocksClient.createConnection = async (options, callback) => { const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); - socket.unref() + socket.unref(); sockets.push(socket); return { socket, From 10bfe596e0272ac5f2ed6283de0a521d5913393b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 13:01:39 +0200 Subject: [PATCH 23/43] test --- src/mongoPatch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 419d3d1..bbf83a5 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -28,7 +28,7 @@ export function useProxyForMongo(config: Config) { console.log(`Closing ${sockets.length} open proxy sockets`); for (const socket of sockets) { await new Promise((resolve, reject) => { - socket.on('close', () => resolve); + socket.on('close', () => resolve(null)); socket.end(); }); } From 673e7ac6273fc631872507074272a0ca29fb2896 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 13:10:36 +0200 Subject: [PATCH 24/43] test --- src/mongoPatch.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index bbf83a5..1621bd1 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -26,12 +26,16 @@ export function useProxyForMongo(config: Config) { return { close: async () => { console.log(`Closing ${sockets.length} open proxy sockets`); - for (const socket of sockets) { - await new Promise((resolve, reject) => { - socket.on('close', () => resolve(null)); - socket.end(); - }); - } + await Promise.all( + sockets.map( + (socket) => + new Promise((resolve) => { + socket.once('close', resolve); + socket.destroy(); + }), + ), + ); + sockets.length = 0; }, }; } From 203fdc6f71355e6f259de2270b60f55cd58acd25 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 13:29:59 +0200 Subject: [PATCH 25/43] test --- src/mongoPatch.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 1621bd1..0350faa 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -8,6 +8,9 @@ interface Config { /** The journey apps cc egress proxy domain */ proxy: string; } + +const originalCreateConnection = socks.SocksClient.createConnection; + /** * The patch should be called before instantiating the MongoClient * @param config - The configuration for the proxy @@ -30,12 +33,16 @@ export function useProxyForMongo(config: Config) { sockets.map( (socket) => new Promise((resolve) => { - socket.once('close', resolve); + socket.once('close', ()=>{ + console.log('Socket closed'); + resolve(); + }); socket.destroy(); }), ), ); sockets.length = 0; + socks.SocksClient.createConnection = originalCreateConnection; }, }; } From 0d5adce234118f968f7b1fcc20df754d8f2cb0ec Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 13:36:16 +0200 Subject: [PATCH 26/43] test exit --- src/mongoPatch.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 0350faa..5677750 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -28,21 +28,23 @@ export function useProxyForMongo(config: Config) { }; return { close: async () => { - console.log(`Closing ${sockets.length} open proxy sockets`); + let count = 0; await Promise.all( sockets.map( (socket) => new Promise((resolve) => { - socket.once('close', ()=>{ - console.log('Socket closed'); + socket.once('close', () => { + count++; resolve(); }); socket.destroy(); }), ), ); - sockets.length = 0; - socks.SocksClient.createConnection = originalCreateConnection; + if (count === sockets.length) { + console.log(`Closed ${sockets.length} MongoDB connection sockets`); + process.exit(0); + } }, }; } From a826e0ceccf9f1da3cce0872e72e1c63638a4616 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 14:00:21 +0200 Subject: [PATCH 27/43] sockets --- src/mongoPatch.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 5677750..243d696 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -20,7 +20,6 @@ export function useProxyForMongo(config: Config) { socks.SocksClient.createConnection = async (options, callback) => { const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); - socket.unref(); sockets.push(socket); return { socket, @@ -37,13 +36,12 @@ export function useProxyForMongo(config: Config) { count++; resolve(); }); - socket.destroy(); + socket.end(); }), ), ); if (count === sockets.length) { console.log(`Closed ${sockets.length} MongoDB connection sockets`); - process.exit(0); } }, }; From 69f7da7ae58883ce21490ec70bf8583e6fdad837 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 14:05:10 +0200 Subject: [PATCH 28/43] destroy socket --- src/mongoPatch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 243d696..286aa9f 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -36,7 +36,7 @@ export function useProxyForMongo(config: Config) { count++; resolve(); }); - socket.end(); + socket.destroy(); }), ), ); From 6d67c91345187c864f851a0bd842e0a034ffae05 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 14:25:01 +0200 Subject: [PATCH 29/43] revert --- src/mongoPatch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 286aa9f..243d696 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -36,7 +36,7 @@ export function useProxyForMongo(config: Config) { count++; resolve(); }); - socket.destroy(); + socket.end(); }), ), ); From ca68c61f42900df3461f603d04b43a60f9c78639 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 22:02:48 +0200 Subject: [PATCH 30/43] trying to find the hang --- src/HttpsProxySocket.ts | 18 +++++++++--------- src/mongoPatch.ts | 2 -- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/HttpsProxySocket.ts b/src/HttpsProxySocket.ts index 0590a23..93873fa 100644 --- a/src/HttpsProxySocket.ts +++ b/src/HttpsProxySocket.ts @@ -3,9 +3,9 @@ import { createProxyAgent } from './createProxyAgent'; import { setServername } from './utils/setServername'; import { parseOptions } from './utils/parseOptions'; -import { debug as nodeDebug } from 'util'; - -const debug = nodeDebug('https-proxy'); +// import { debug as nodeDebug } from 'util'; +// +// const debug = nodeDebug('https-proxy'); export interface HttpsProxyConfig extends tls.ConnectionOptions { headers?: { [key: string]: string }; @@ -38,7 +38,7 @@ export class HttpsProxySocket { if (!options) { throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!'); } - debug('creating new HttpsProxyAgent instance: %o', sanitizedOptions); + console.log('creating new HttpsProxyAgent instance: %o', sanitizedOptions); this.proxyConfig = proxyConfig || {}; this.proxy = sanitizedOptions as tls.ConnectionOptions; @@ -87,7 +87,7 @@ export class HttpsProxySocket { let buffersLength = 0; function read() { - var b = socket.read(); + const b = socket.read(); if (b) { ondata(b); } else { @@ -104,11 +104,11 @@ export class HttpsProxySocket { } function onclose(err: any) { - debug('onclose had error %o', err); + console.log('onclose had error %o', err); } function onend() { - debug('onend'); + console.log('onend'); } function onerror(err: any) { @@ -129,7 +129,7 @@ export class HttpsProxySocket { if (str.indexOf(END_OF_HEADERS) < 0) { // keep buffering - debug('have not received end of HTTP headers yet...'); + console.log('have not received end of HTTP headers yet...'); if (socket.readable) { read(); } else { @@ -140,7 +140,7 @@ export class HttpsProxySocket { const firstLine = str.substring(0, str.indexOf('\r\n')); const statusCode = parseInt(firstLine.split(' ')[1], 10); - debug('got proxy server response: %o', firstLine); + console.log('got proxy server response: %o', firstLine); if (200 == statusCode) { // 200 Connected status code! diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 243d696..add0543 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -9,8 +9,6 @@ interface Config { proxy: string; } -const originalCreateConnection = socks.SocksClient.createConnection; - /** * The patch should be called before instantiating the MongoClient * @param config - The configuration for the proxy From f95c3a40fbceaac6892b64269ebe7fe79eb40acc Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 22:13:54 +0200 Subject: [PATCH 31/43] removed cleanup --- src/HttpsProxySocket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpsProxySocket.ts b/src/HttpsProxySocket.ts index 93873fa..a369812 100644 --- a/src/HttpsProxySocket.ts +++ b/src/HttpsProxySocket.ts @@ -149,7 +149,7 @@ export class HttpsProxySocket { // nullify the buffered data since we won't be needing it buffers = []; - cleanup(); + // cleanup(); cb(null, sock); } else { // some other status code that's not 200... need to re-play the HTTP header From 98ca8498bd312da1dc7cd3f7a4f5ce166649ebcc Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 22:33:10 +0200 Subject: [PATCH 32/43] single proxy --- src/HttpsProxySocket.ts | 2 +- src/mongoPatch.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/HttpsProxySocket.ts b/src/HttpsProxySocket.ts index a369812..93873fa 100644 --- a/src/HttpsProxySocket.ts +++ b/src/HttpsProxySocket.ts @@ -149,7 +149,7 @@ export class HttpsProxySocket { // nullify the buffered data since we won't be needing it buffers = []; - // cleanup(); + cleanup(); cb(null, sock); } else { // some other status code that's not 200... need to re-play the HTTP header diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index add0543..5e2bc73 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -15,9 +15,9 @@ interface Config { */ export function useProxyForMongo(config: Config) { const sockets: tls.TLSSocket[] = []; + let proxy: HttpsProxySocket | undefined = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); socks.SocksClient.createConnection = async (options, callback) => { - const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); - const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); + const socket = await proxy!.connect({ host: options.destination.host, port: options.destination.port }); sockets.push(socket); return { socket, @@ -38,6 +38,7 @@ export function useProxyForMongo(config: Config) { }), ), ); + proxy = undefined; if (count === sockets.length) { console.log(`Closed ${sockets.length} MongoDB connection sockets`); } From 6c9481a87d45e20efb6fbe9a8b3eddff2460af28 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 23:09:18 +0200 Subject: [PATCH 33/43] test --- src/HttpsProxySocket.ts | 16 ++++++++-------- src/mongoPatch.ts | 13 ++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/HttpsProxySocket.ts b/src/HttpsProxySocket.ts index 93873fa..735ddc5 100644 --- a/src/HttpsProxySocket.ts +++ b/src/HttpsProxySocket.ts @@ -3,9 +3,9 @@ import { createProxyAgent } from './createProxyAgent'; import { setServername } from './utils/setServername'; import { parseOptions } from './utils/parseOptions'; -// import { debug as nodeDebug } from 'util'; -// -// const debug = nodeDebug('https-proxy'); +import { debug as nodeDebug } from 'util'; + +const debug = nodeDebug('https-proxy'); export interface HttpsProxyConfig extends tls.ConnectionOptions { headers?: { [key: string]: string }; @@ -38,7 +38,7 @@ export class HttpsProxySocket { if (!options) { throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!'); } - console.log('creating new HttpsProxyAgent instance: %o', sanitizedOptions); + debug('creating new HttpsProxyAgent instance: %o', sanitizedOptions); this.proxyConfig = proxyConfig || {}; this.proxy = sanitizedOptions as tls.ConnectionOptions; @@ -104,11 +104,11 @@ export class HttpsProxySocket { } function onclose(err: any) { - console.log('onclose had error %o', err); + debug('onclose had error %o', err); } function onend() { - console.log('onend'); + debug('onend'); } function onerror(err: any) { @@ -129,7 +129,7 @@ export class HttpsProxySocket { if (str.indexOf(END_OF_HEADERS) < 0) { // keep buffering - console.log('have not received end of HTTP headers yet...'); + debug('have not received end of HTTP headers yet...'); if (socket.readable) { read(); } else { @@ -140,7 +140,7 @@ export class HttpsProxySocket { const firstLine = str.substring(0, str.indexOf('\r\n')); const statusCode = parseInt(firstLine.split(' ')[1], 10); - console.log('got proxy server response: %o', firstLine); + debug('got proxy server response: %o', firstLine); if (200 == statusCode) { // 200 Connected status code! diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 5e2bc73..f085b3e 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -15,9 +15,15 @@ interface Config { */ export function useProxyForMongo(config: Config) { const sockets: tls.TLSSocket[] = []; - let proxy: HttpsProxySocket | undefined = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); + const proxy: HttpsProxySocket = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); socks.SocksClient.createConnection = async (options, callback) => { - const socket = await proxy!.connect({ host: options.destination.host, port: options.destination.port }); + const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); + + socket.on('error', (err) => { + if (err) { + console.error('MongoDB connection socket error:', err); + } + }); sockets.push(socket); return { socket, @@ -32,13 +38,14 @@ export function useProxyForMongo(config: Config) { new Promise((resolve) => { socket.once('close', () => { count++; + socket.removeAllListeners(); + socket.destroySoon(); resolve(); }); socket.end(); }), ), ); - proxy = undefined; if (count === sockets.length) { console.log(`Closed ${sockets.length} MongoDB connection sockets`); } From 540db4243fd4c759aad2223322fd44ca8eb659aa Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Tue, 27 Jan 2026 23:18:15 +0200 Subject: [PATCH 34/43] destroy with error --- src/mongoPatch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index f085b3e..3907513 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -39,7 +39,8 @@ export function useProxyForMongo(config: Config) { socket.once('close', () => { count++; socket.removeAllListeners(); - socket.destroySoon(); + socket.unref(); + socket.destroy(new Error('Socket closed by user')); resolve(); }); socket.end(); From 7ede132b10245406f900d9d0eff9afeab890bc9b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 08:00:38 +0200 Subject: [PATCH 35/43] socket status --- src/mongoPatch.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 3907513..c6e97fd 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -15,14 +15,14 @@ interface Config { */ export function useProxyForMongo(config: Config) { const sockets: tls.TLSSocket[] = []; - const proxy: HttpsProxySocket = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }); socks.SocksClient.createConnection = async (options, callback) => { - const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port }); + const socket = await new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }).connect({ + host: options.destination.host, + port: options.destination.port, + }); - socket.on('error', (err) => { - if (err) { - console.error('MongoDB connection socket error:', err); - } + socket.on('timeout', () => { + console.error('Socket timeout'); }); sockets.push(socket); return { @@ -38,9 +38,6 @@ export function useProxyForMongo(config: Config) { new Promise((resolve) => { socket.once('close', () => { count++; - socket.removeAllListeners(); - socket.unref(); - socket.destroy(new Error('Socket closed by user')); resolve(); }); socket.end(); @@ -50,6 +47,7 @@ export function useProxyForMongo(config: Config) { if (count === sockets.length) { console.log(`Closed ${sockets.length} MongoDB connection sockets`); } + console.log(sockets); }, }; } From b119392efacd270cfb8d1892d255cdfd8b8d7585 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 08:18:59 +0200 Subject: [PATCH 36/43] logs --- src/mongoPatch.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index c6e97fd..ed0f358 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -36,7 +36,7 @@ export function useProxyForMongo(config: Config) { sockets.map( (socket) => new Promise((resolve) => { - socket.once('close', () => { + socket.once('finish', () => { count++; resolve(); }); @@ -44,10 +44,18 @@ export function useProxyForMongo(config: Config) { }), ), ); - if (count === sockets.length) { - console.log(`Closed ${sockets.length} MongoDB connection sockets`); + // if (count === sockets.length) { + // console.log(`Closed ${sockets.length} MongoDB connection sockets`); + // } + for (const socket of sockets) { + console.log('---------------------------------------------'); + console.log('Socket destroyed', socket.destroyed); + console.log('Socket readable', socket.readable); + console.log('Socket writable', socket.writable); + console.log('Socket closed', socket.closed); + console.log('---------------------------------------------'); } - console.log(sockets); + sockets.length = 0; }, }; } From 249d70759461bb010d2562c057b891fc9cfb9df3 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 08:25:51 +0200 Subject: [PATCH 37/43] testing --- src/mongoPatch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index ed0f358..b83b84f 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -36,11 +36,11 @@ export function useProxyForMongo(config: Config) { sockets.map( (socket) => new Promise((resolve) => { - socket.once('finish', () => { + socket.once('close', () => { count++; resolve(); }); - socket.end(); + socket.destroySoon(); }), ), ); From 4d8420ad6fa93aaaa40236f888fc779303777907 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 08:36:43 +0200 Subject: [PATCH 38/43] refactor --- src/mongoPatch.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index b83b84f..10a1fe5 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -14,7 +14,7 @@ interface Config { * @param config - The configuration for the proxy */ export function useProxyForMongo(config: Config) { - const sockets: tls.TLSSocket[] = []; + let sockets: tls.TLSSocket[] = []; socks.SocksClient.createConnection = async (options, callback) => { const socket = await new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }).connect({ host: options.destination.host, @@ -31,31 +31,21 @@ export function useProxyForMongo(config: Config) { }; return { close: async () => { - let count = 0; await Promise.all( sockets.map( (socket) => new Promise((resolve) => { socket.once('close', () => { - count++; + console.log( + `Socket state: destroyed=${socket.destroyed}, readable=${socket.readable}, writable=${socket.writable}, closed=${socket.closed}`, + ); resolve(); }); socket.destroySoon(); }), ), ); - // if (count === sockets.length) { - // console.log(`Closed ${sockets.length} MongoDB connection sockets`); - // } - for (const socket of sockets) { - console.log('---------------------------------------------'); - console.log('Socket destroyed', socket.destroyed); - console.log('Socket readable', socket.readable); - console.log('Socket writable', socket.writable); - console.log('Socket closed', socket.closed); - console.log('---------------------------------------------'); - } - sockets.length = 0; + sockets = []; }, }; } From 50e138e94b916b34a10da50f4e338d28c1c97e7d Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 10:45:21 +0200 Subject: [PATCH 39/43] test --- src/mongoPatch.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 10a1fe5..27daade 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -31,20 +31,23 @@ export function useProxyForMongo(config: Config) { }; return { close: async () => { - await Promise.all( - sockets.map( - (socket) => - new Promise((resolve) => { - socket.once('close', () => { - console.log( - `Socket state: destroyed=${socket.destroyed}, readable=${socket.readable}, writable=${socket.writable}, closed=${socket.closed}`, - ); - resolve(); - }); - socket.destroySoon(); - }), - ), - ); + // await Promise.all( + // sockets.map( + // (socket) => + // new Promise((resolve) => { + // socket.once('close', () => { + // console.log( + // `Socket state: destroyed=${socket.destroyed}, readable=${socket.readable}, writable=${socket.writable}, closed=${socket.closed}`, + // ); + // resolve(); + // }); + // socket.destroySoon(); + // }), + // ), + // ); + for (const socket of sockets) { + socket.destroySoon(); + } sockets = []; }, }; From d3b0e046fca578c8dc184efa59bca83dfbc54d4b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 11:32:02 +0200 Subject: [PATCH 40/43] destroy existing socket --- src/mongoPatch.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index 27daade..d938825 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -16,6 +16,7 @@ interface Config { export function useProxyForMongo(config: Config) { let sockets: tls.TLSSocket[] = []; socks.SocksClient.createConnection = async (options, callback) => { + options.existing_socket?.destroy(); const socket = await new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }).connect({ host: options.destination.host, port: options.destination.port, @@ -31,23 +32,17 @@ export function useProxyForMongo(config: Config) { }; return { close: async () => { - // await Promise.all( - // sockets.map( - // (socket) => - // new Promise((resolve) => { - // socket.once('close', () => { - // console.log( - // `Socket state: destroyed=${socket.destroyed}, readable=${socket.readable}, writable=${socket.writable}, closed=${socket.closed}`, - // ); - // resolve(); - // }); - // socket.destroySoon(); - // }), - // ), - // ); - for (const socket of sockets) { - socket.destroySoon(); - } + await Promise.all( + sockets.map( + (socket) => + new Promise((resolve) => { + socket.once('close', () => { + resolve(); + }); + socket.destroySoon(); + }), + ), + ); sockets = []; }, }; From c750a23bb5138cb1ba27e47b173ff027621b5540 Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 11:44:02 +0200 Subject: [PATCH 41/43] add existing socket to mongo proxy --- src/mongoPatch.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mongoPatch.ts b/src/mongoPatch.ts index d938825..bbaa5cb 100644 --- a/src/mongoPatch.ts +++ b/src/mongoPatch.ts @@ -16,8 +16,7 @@ interface Config { export function useProxyForMongo(config: Config) { let sockets: tls.TLSSocket[] = []; socks.SocksClient.createConnection = async (options, callback) => { - options.existing_socket?.destroy(); - const socket = await new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }).connect({ + const socket = await new HttpsProxySocket({ socket: options.existing_socket }, { auth: config.auth }).connect({ host: options.destination.host, port: options.destination.port, }); From 312a9dc6fc545c4b274fd4212f17b894209173dc Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 11:46:38 +0200 Subject: [PATCH 42/43] fix workflow --- .github/workflows/release.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3f689a4..00e16f6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,15 +45,15 @@ jobs: - name: Build run: pnpm build - # - name: Create Release Pull Request or Publish to npm - # id: changesets - # uses: changesets/action@v1 - # if: ${{ github.event_name == 'push' }} - # with: - # version: pnpm ci:version - # publish: pnpm ci:publish - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create Release Pull Request or Publish to npm + id: changesets + uses: changesets/action@v1 + if: ${{ github.event_name == 'push' }} + with: + version: pnpm ci:version + publish: pnpm ci:publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Dev publish if: ${{ github.event_name == 'workflow_dispatch' }} From 0050a5dfa3eb4ff325df11b281faede0cde15a7b Mon Sep 17 00:00:00 2001 From: EspressoTrip-v2 Date: Wed, 28 Jan 2026 11:48:20 +0200 Subject: [PATCH 43/43] version bump --- .changeset/quiet-melons-chew.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/quiet-melons-chew.md diff --git a/.changeset/quiet-melons-chew.md b/.changeset/quiet-melons-chew.md new file mode 100644 index 0000000..fc1a84b --- /dev/null +++ b/.changeset/quiet-melons-chew.md @@ -0,0 +1,5 @@ +--- +'@journeyapps/https-proxy-socket': patch +--- + +Fixed socket timeout and use mongo driver existing socket