Skip to content

Commit 8d0eb0f

Browse files
Merge pull request #23 from journeyapps/fix_for_multiple_connections
Fix for multiple connections
2 parents 5fb8db7 + a3b453b commit 8d0eb0f

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

.changeset/quiet-melons-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/https-proxy-socket': patch
3+
---
4+
5+
Fixed socket timeout and use mongo driver existing socket

.changeset/vast-memes-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/https-proxy-socket': patch
3+
---
4+
5+
Mongo hack fix, multi socket closure

.github/workflows/release.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ jobs:
4545
- name: Build
4646
run: pnpm build
4747

48-
# - name: Create Release Pull Request or Publish to npm
49-
# id: changesets
50-
# uses: changesets/action@v1
51-
# if: ${{ github.event_name == 'push' }}
52-
# with:
53-
# version: pnpm ci:version
54-
# publish: pnpm ci:publish
55-
# env:
56-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
- name: Create Release Pull Request or Publish to npm
49+
id: changesets
50+
uses: changesets/action@v1
51+
if: ${{ github.event_name == 'push' }}
52+
with:
53+
version: pnpm ci:version
54+
publish: pnpm ci:publish
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757

5858
- name: Dev publish
5959
if: ${{ github.event_name == 'workflow_dispatch' }}

src/HttpsProxySocket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class HttpsProxySocket {
8787
let buffersLength = 0;
8888

8989
function read() {
90-
var b = socket.read();
90+
const b = socket.read();
9191
if (b) {
9292
ondata(b);
9393
} else {

src/mongoPatch.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,41 @@ interface Config {
88
/** The journey apps cc egress proxy domain */
99
proxy: string;
1010
}
11+
1112
/**
1213
* The patch should be called before instantiating the MongoClient
1314
* @param config - The configuration for the proxy
1415
*/
1516
export function useProxyForMongo(config: Config) {
16-
let socket: tls.TLSSocket;
17+
let sockets: tls.TLSSocket[] = [];
1718
socks.SocksClient.createConnection = async (options, callback) => {
18-
const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth });
19-
return new Promise(async (resolve, reject) => {
20-
socket = await proxy.connect({ host: options.destination.host, port: options.destination.port });
21-
resolve({
22-
socket,
23-
});
19+
const socket = await new HttpsProxySocket({ socket: options.existing_socket }, { auth: config.auth }).connect({
20+
host: options.destination.host,
21+
port: options.destination.port,
22+
});
23+
24+
socket.on('timeout', () => {
25+
console.error('Socket timeout');
2426
});
27+
sockets.push(socket);
28+
return {
29+
socket,
30+
};
2531
};
2632
return {
27-
close: () => socket?.end(),
33+
close: async () => {
34+
await Promise.all(
35+
sockets.map(
36+
(socket) =>
37+
new Promise<void>((resolve) => {
38+
socket.once('close', () => {
39+
resolve();
40+
});
41+
socket.destroySoon();
42+
}),
43+
),
44+
);
45+
sockets = [];
46+
},
2847
};
2948
}

0 commit comments

Comments
 (0)