File tree Expand file tree Collapse file tree 5 files changed +47
-18
lines changed
Expand file tree Collapse file tree 5 files changed +47
-18
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @journeyapps/https-proxy-socket ' : patch
3+ ---
4+
5+ Fixed socket timeout and use mongo driver existing socket
Original file line number Diff line number Diff line change 1+ ---
2+ ' @journeyapps/https-proxy-socket ' : patch
3+ ---
4+
5+ Mongo hack fix, multi socket closure
Original file line number Diff line number Diff 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' }}
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 */
1516export 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}
You can’t perform that action at this time.
0 commit comments