File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -13,17 +13,23 @@ interface Config {
1313 * @param config - The configuration for the proxy
1414 */
1515export 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}
You can’t perform that action at this time.
0 commit comments