@@ -219,6 +219,7 @@ class ErrorHandler {
219
219
this . resOrSocket = null
220
220
this . callback = null
221
221
222
+ this . _release = this . _release . bind ( this )
222
223
this . _handle = this . _handle . bind ( this )
223
224
this . _handle . requestTimeout = this . _requestTimeout . bind ( this )
224
225
}
@@ -246,28 +247,27 @@ class ErrorHandler {
246
247
247
248
if ( this . callback ) {
248
249
this . callback ( err , this . req , this . resOrSocket )
249
- ErrorHandler . release ( this )
250
250
} else {
251
- ErrorHandler . release ( this )
252
251
throw err
253
252
}
254
253
}
255
254
256
- static create ( req , resOrSocket , callback ) {
257
- const errorHandler = ErrorHandler . pool . pop ( ) || new ErrorHandler ( )
258
- errorHandler . hasError = false
259
- errorHandler . req = req
260
- errorHandler . resOrSocket = resOrSocket
261
- errorHandler . callback = callback
262
- return errorHandler . _handle
255
+ _release ( ) {
256
+ this . hasError = false
257
+ this . req = null
258
+ this . resOrSocket = null
259
+ this . callback = null
260
+ ErrorHandler . pool . push ( this )
263
261
}
264
262
265
- static release ( obj ) {
266
- obj . hasError = false
267
- obj . req = null
268
- obj . resOrSocket = null
269
- obj . callback = null
270
- ErrorHandler . pool . push ( obj )
263
+ static create ( req , resOrSocket , callback ) {
264
+ const handler = ErrorHandler . pool . pop ( ) || new ErrorHandler ( )
265
+ handler . hasError = false
266
+ handler . req = req
267
+ handler . resOrSocket = resOrSocket
268
+ handler . callback = callback
269
+ handler . req . on ( 'close' , handler . _release )
270
+ return handler . _handle
271
271
}
272
272
}
273
273
ErrorHandler . pool = [ ]
@@ -279,18 +279,12 @@ class ProxyErrorHandler {
279
279
this . proxyReq = null
280
280
this . onError = null
281
281
282
- this . _handle = this . _handle . bind ( this )
283
282
this . _release = this . _release . bind ( this )
283
+ this . _handle = this . _handle . bind ( this )
284
284
this . _handle . gatewayTimeout = this . _gatewayTimeout . bind ( this )
285
285
this . _handle . socketHangup = this . _socketHangup . bind ( this )
286
286
}
287
287
288
- _abort ( ) {
289
- if ( ! this . proxyReq . aborted ) {
290
- this . proxyReq . abort ( )
291
- }
292
- }
293
-
294
288
_handle ( err ) {
295
289
if ( this . hasError ) {
296
290
return
@@ -322,12 +316,14 @@ class ProxyErrorHandler {
322
316
this . _handle ( createError ( 'socket hang up' , 'ECONNRESET' , 502 ) )
323
317
}
324
318
325
- _release ( ) {
326
- this . req . removeListener ( 'close' , this . _release )
327
-
328
- if ( this . hasError ) {
329
- this . _abort ( )
319
+ _abort ( ) {
320
+ if ( ! this . proxyReq . aborted ) {
321
+ this . proxyReq . abort ( )
330
322
}
323
+ }
324
+
325
+ _release ( ) {
326
+ this . _abort ( )
331
327
332
328
this . hasError = null
333
329
this . req = null
@@ -406,8 +402,6 @@ class ProxyResponseHandler {
406
402
}
407
403
408
404
_release ( ) {
409
- this . req . removeListener ( 'close' , this . _release )
410
-
411
405
this . req = null
412
406
this . resOrSocket = null
413
407
this . onRes = null
@@ -426,10 +420,6 @@ class ProxyResponseHandler {
426
420
handler . req . on ( 'close' , handler . _release )
427
421
return handler . _handle
428
422
}
429
-
430
- static release ( obj ) {
431
- ProxyResponseHandler . pool . push ( obj )
432
- }
433
423
}
434
424
ProxyResponseHandler . pool = [ ]
435
425
@@ -441,8 +431,8 @@ class ProxyUpgradeHandler {
441
431
this . proxyRes = null
442
432
this . proxySocket = null
443
433
444
- this . _handle = this . _handle . bind ( this )
445
434
this . _release = this . _release . bind ( this )
435
+ this . _handle = this . _handle . bind ( this )
446
436
}
447
437
448
438
_handle ( proxyRes , proxySocket , proxyHead ) {
@@ -486,7 +476,6 @@ class ProxyUpgradeHandler {
486
476
}
487
477
488
478
_release ( ) {
489
- this . req . removeListener ( 'close' , this . _release )
490
479
this . proxyRes . destroy ( )
491
480
this . proxySocket . destroy ( )
492
481
@@ -506,9 +495,5 @@ class ProxyUpgradeHandler {
506
495
handler . req . on ( 'close' , handler . _release )
507
496
return handler . _handle
508
497
}
509
-
510
- static release ( obj ) {
511
- ProxyUpgradeHandler . pool . push ( obj )
512
- }
513
498
}
514
499
ProxyUpgradeHandler . pool = [ ]
0 commit comments