@@ -60,7 +60,7 @@ class ALPNCache {
60
60
ALPNProtocols : [ 'h2' , 'http/1.1' ] ,
61
61
rejectUnauthorized : false ,
62
62
} ) . then ( socket => {
63
- socket . on ( 'secureConnect' , ( ) => {
63
+ socket . once ( 'secureConnect' , ( ) => {
64
64
// The server may not respond with ALPN, in which case we default to http/1.1.
65
65
result . resolve ( socket . alpnProtocol || 'http/1.1' ) ;
66
66
socket . end ( ) ;
@@ -93,8 +93,8 @@ class SocksProxyConnection {
93
93
94
94
async connect ( ) {
95
95
this . target = await createSocket ( rewriteToLocalhostIfNeeded ( this . host ) , this . port ) ;
96
- this . target . on ( 'close' , this . _targetCloseEventListener ) ;
97
- this . target . on ( 'error' , error => this . socksProxy . _socksProxy . sendSocketError ( { uid : this . uid , error : error . message } ) ) ;
96
+ this . target . once ( 'close' , this . _targetCloseEventListener ) ;
97
+ this . target . once ( 'error' , error => this . socksProxy . _socksProxy . sendSocketError ( { uid : this . uid , error : error . message } ) ) ;
98
98
this . socksProxy . _socksProxy . socketConnected ( {
99
99
uid : this . uid ,
100
100
host : this . target . localAddress ! ,
@@ -138,9 +138,9 @@ class SocksProxyConnection {
138
138
...dummyServerTlsOptions ,
139
139
ALPNProtocols : alpnProtocolChosenByServer === 'h2' ? [ 'h2' , 'http/1.1' ] : [ 'http/1.1' ] ,
140
140
} ) ;
141
- this . internal ?. on ( 'close' , ( ) => dummyServer . close ( ) ) ;
141
+ this . internal ?. once ( 'close' , ( ) => dummyServer . close ( ) ) ;
142
142
dummyServer . emit ( 'connection' , this . internal ) ;
143
- dummyServer . on ( 'secureConnection' , internalTLS => {
143
+ dummyServer . once ( 'secureConnection' , internalTLS => {
144
144
debugLogger . log ( 'client-certificates' , `Browser->Proxy ${ this . host } :${ this . port } chooses ALPN ${ internalTLS . alpnProtocol } ` ) ;
145
145
146
146
let targetTLS : tls . TLSSocket | undefined = undefined ;
@@ -162,7 +162,7 @@ class SocksProxyConnection {
162
162
this . target . removeListener ( 'close' , this . _targetCloseEventListener ) ;
163
163
// @ts -expect-error
164
164
const session : http2 . ServerHttp2Session = http2 . performServerHandshake ( internalTLS ) ;
165
- session . on ( 'stream' , ( stream : http2 . ServerHttp2Stream ) => {
165
+ session . once ( 'stream' , ( stream : http2 . ServerHttp2Stream ) => {
166
166
stream . respond ( {
167
167
'content-type' : 'text/html' ,
168
168
[ http2 . constants . HTTP2_HEADER_STATUS ] : 503 ,
@@ -171,7 +171,7 @@ class SocksProxyConnection {
171
171
session . close ( ) ;
172
172
closeBothSockets ( ) ;
173
173
} ) ;
174
- stream . on ( 'error' , ( ) => closeBothSockets ( ) ) ;
174
+ stream . once ( 'error' , ( ) => closeBothSockets ( ) ) ;
175
175
} ) ;
176
176
} else {
177
177
closeBothSockets ( ) ;
@@ -208,16 +208,16 @@ class SocksProxyConnection {
208
208
209
209
targetTLS = tls . connect ( tlsOptions ) ;
210
210
211
- targetTLS . on ( 'secureConnect' , ( ) => {
211
+ targetTLS . once ( 'secureConnect' , ( ) => {
212
212
internalTLS . pipe ( targetTLS ) ;
213
213
targetTLS . pipe ( internalTLS ) ;
214
214
} ) ;
215
215
216
- internalTLS . on ( 'end' , ( ) => closeBothSockets ( ) ) ;
217
- targetTLS . on ( 'end' , ( ) => closeBothSockets ( ) ) ;
216
+ internalTLS . once ( 'end' , ( ) => closeBothSockets ( ) ) ;
217
+ targetTLS . once ( 'end' , ( ) => closeBothSockets ( ) ) ;
218
218
219
- internalTLS . on ( 'error' , ( ) => closeBothSockets ( ) ) ;
220
- targetTLS . on ( 'error' , handleError ) ;
219
+ internalTLS . once ( 'error' , ( ) => closeBothSockets ( ) ) ;
220
+ targetTLS . once ( 'error' , handleError ) ;
221
221
} ) ;
222
222
} ) ;
223
223
}
0 commit comments