Skip to content

Commit 7ede132

Browse files
socket status
1 parent 540db42 commit 7ede132

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/mongoPatch.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ interface Config {
1515
*/
1616
export function useProxyForMongo(config: Config) {
1717
const sockets: tls.TLSSocket[] = [];
18-
const proxy: HttpsProxySocket = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth });
1918
socks.SocksClient.createConnection = async (options, callback) => {
20-
const socket = await proxy.connect({ host: options.destination.host, port: options.destination.port });
19+
const socket = await new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth }).connect({
20+
host: options.destination.host,
21+
port: options.destination.port,
22+
});
2123

22-
socket.on('error', (err) => {
23-
if (err) {
24-
console.error('MongoDB connection socket error:', err);
25-
}
24+
socket.on('timeout', () => {
25+
console.error('Socket timeout');
2626
});
2727
sockets.push(socket);
2828
return {
@@ -38,9 +38,6 @@ export function useProxyForMongo(config: Config) {
3838
new Promise<void>((resolve) => {
3939
socket.once('close', () => {
4040
count++;
41-
socket.removeAllListeners();
42-
socket.unref();
43-
socket.destroy(new Error('Socket closed by user'));
4441
resolve();
4542
});
4643
socket.end();
@@ -50,6 +47,7 @@ export function useProxyForMongo(config: Config) {
5047
if (count === sockets.length) {
5148
console.log(`Closed ${sockets.length} MongoDB connection sockets`);
5249
}
50+
console.log(sockets);
5351
},
5452
};
5553
}

0 commit comments

Comments
 (0)