Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-melons-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/https-proxy-socket': patch
---

Fixed socket timeout and use mongo driver existing socket
5 changes: 5 additions & 0 deletions .changeset/vast-memes-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/https-proxy-socket': patch
---

Mongo hack fix, multi socket closure
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
2 changes: 1 addition & 1 deletion src/HttpsProxySocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 27 additions & 8 deletions src/mongoPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,41 @@ interface Config {
/** The journey apps cc egress proxy domain */
proxy: string;
}

/**
* The patch should be called before instantiating the MongoClient
* @param config - The configuration for the proxy
*/
export function useProxyForMongo(config: Config) {
let socket: tls.TLSSocket;
let 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 new HttpsProxySocket({ socket: options.existing_socket }, { auth: config.auth }).connect({
host: options.destination.host,
port: options.destination.port,
});

socket.on('timeout', () => {
console.error('Socket timeout');
});
sockets.push(socket);
return {
socket,
};
};
return {
close: () => socket?.end(),
close: async () => {
await Promise.all(
sockets.map(
(socket) =>
new Promise<void>((resolve) => {
socket.once('close', () => {
resolve();
});
socket.destroySoon();
}),
),
);
sockets = [];
},
};
}
Loading