Skip to content

Commit 940fa05

Browse files
committed
WIP: track multiple sockets for mongo driver's connection pool
1 parent b4f9ea9 commit 940fa05

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/mongoPatch.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ interface Config {
1313
* @param config - The configuration for the proxy
1414
*/
1515
export function useProxyForMongo(config: Config) {
16-
let socket: tls.TLSSocket;
16+
const sockets: tls.TLSSocket[] = [];
1717
socks.SocksClient.createConnection = async (options, callback) => {
1818
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-
});
24-
});
19+
const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port });
20+
sockets.push(socket)
21+
return {
22+
socket
23+
};
2524
};
2625
return {
27-
close: () => socket?.end(),
26+
close: async () => {
27+
for (const socket of sockets) {
28+
await new Promise((resolve, reject) => {
29+
socket.once('close', () => resolve);
30+
socket.end()
31+
})
32+
}
33+
},
2834
};
2935
}

0 commit comments

Comments
 (0)