bdy 1.7.59-dev → 1.7.60-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.7.59-dev",
4
+ "version": "1.7.60-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "dependencies": {
package/src/ssh/client.js CHANGED
@@ -88,12 +88,20 @@ class SshClient extends EventEmitter {
88
88
  async processStream(stream, info) {
89
89
  if (stream.readableFlowing) stream.pause();
90
90
  stream.on('error', () => {
91
- stream.removeAllListeners();
92
91
  try {
93
- stream.close();
92
+ stream.removeAllListeners();
93
+ stream.once('error', () => {});
94
+ stream.end();
94
95
  } catch (err) {
95
96
  // do nothing
96
97
  }
98
+ setTimeout(() => {
99
+ try {
100
+ stream.destroy();
101
+ } catch {
102
+ // do nothing
103
+ }
104
+ }, 1000);
97
105
  });
98
106
  stream.on('close', () => {
99
107
  stream.removeAllListeners();
@@ -29,6 +29,7 @@ class TunnelHttpStream extends Transform {
29
29
  while(this.backPressure.length > 0) {
30
30
  const chunk = this.backPressure.shift();
31
31
  if (!this.push(chunk)) {
32
+ this.removeAllListeners('drain');
32
33
  this.once('drain', () => {
33
34
  this._pushBackPressure();
34
35
  });
@@ -20,9 +20,15 @@ class TunnelLatency extends EventEmitter {
20
20
  let ts = null;
21
21
  const clear = () => {
22
22
  clearTimeout(ts);
23
- socket.removeAllListeners();
24
- socket.once('error', () => {});
25
- socket.end();
23
+ try {
24
+ socket.removeAllListeners();
25
+ socket.once('error', () => {
26
+ });
27
+ socket.end();
28
+ socket.destroy();
29
+ } catch {
30
+ // do nothing
31
+ }
26
32
  socket = null;
27
33
  this.isChecking = false;
28
34
  };
package/src/tunnel/tcp.js CHANGED
@@ -28,6 +28,7 @@ class TunnelTcp extends EventEmitter {
28
28
  } catch (err) {
29
29
  // do nothing
30
30
  }
31
+ const s1 = this.stream;
31
32
  try {
32
33
  this.socket.removeAllListeners();
33
34
  this.socket.once('error', () => {});
@@ -35,6 +36,19 @@ class TunnelTcp extends EventEmitter {
35
36
  } catch(err) {
36
37
  // do nothing
37
38
  }
39
+ const s2 = this.socket;
40
+ setTimeout(() => {
41
+ try {
42
+ s1.destroy();
43
+ } catch {
44
+ // do nothing
45
+ }
46
+ try {
47
+ s2.destroy();
48
+ } catch {
49
+ // do nothing
50
+ }
51
+ }, 1000);
38
52
  this.socket = null;
39
53
  this.stream = null;
40
54
  this.host = null;
package/src/tunnel.js CHANGED
@@ -510,9 +510,26 @@ class Tunnel extends EventEmitter {
510
510
  return this.type === TUNNEL_HTTP;
511
511
  }
512
512
 
513
+ safeEndStream(stream) {
514
+ try {
515
+ stream.removeAllListeners();
516
+ stream.once('error', () => {});
517
+ stream.end();
518
+ } catch {
519
+ // do nothing
520
+ }
521
+ setTimeout(() => {
522
+ try {
523
+ stream.destroy();
524
+ } catch {
525
+ // do nothing
526
+ }
527
+ }, 1000);
528
+ }
529
+
513
530
  sshStreamTcp(stream) {
514
531
  if (!this.canStreamTcp()) {
515
- stream.end();
532
+ this.safeEndStream(stream);
516
533
  return;
517
534
  }
518
535
  logger.debug(LOG_TUNNEL_TCP_STREAM(this.id));
@@ -524,7 +541,7 @@ class Tunnel extends EventEmitter {
524
541
 
525
542
  sshStreamHttp1(stream, info, ip) {
526
543
  if (!this.canStreamHttp()) {
527
- stream.end();
544
+ this.safeEndStream(stream);
528
545
  return;
529
546
  }
530
547
  logger.debug(LOG_TUNNEL_HTTP1_STREAM(this.id));
@@ -532,12 +549,12 @@ class Tunnel extends EventEmitter {
532
549
  this.http1server.handleSshTunnel(stream, info, ip);
533
550
  return;
534
551
  }
535
- stream.end();
552
+ this.safeEndStream(stream);
536
553
  }
537
554
 
538
555
  sshStreamHttp2(stream, info, ip) {
539
556
  if (!this.canStreamHttp()) {
540
- stream.end();
557
+ this.safeEndStream(stream);
541
558
  return;
542
559
  }
543
560
  logger.debug(LOG_TUNNEL_HTTP2_STREAM(this.id));
@@ -545,12 +562,12 @@ class Tunnel extends EventEmitter {
545
562
  this.http2server.handleSshTunnel(stream, info, ip);
546
563
  return;
547
564
  }
548
- stream.end();
565
+ this.safeEndStream(stream);
549
566
  }
550
567
 
551
568
  sshStreamSsh(stream) {
552
569
  if (!this.canStreamSsh()) {
553
- stream.end();
570
+ this.safeEndStream(stream);
554
571
  return;
555
572
  }
556
573
  logger.debug(LOG_TUNNEL_SSH_STREAM(this.id));
@@ -558,12 +575,12 @@ class Tunnel extends EventEmitter {
558
575
  this.sshServer.handleSshTunnel(stream);
559
576
  return;
560
577
  }
561
- stream.end();
578
+ this.safeEndStream(stream);
562
579
  }
563
580
 
564
581
  sshStreamTls(stream) {
565
582
  if (!this.canStreamTls()) {
566
- stream.end();
583
+ this.safeEndStream(stream);
567
584
  return;
568
585
  }
569
586
  if (this.terminate === TLS_TERMINATE_AT_TARGET) {
@@ -581,7 +598,7 @@ class Tunnel extends EventEmitter {
581
598
  this.tls.handleSshTunnel(stream);
582
599
  return;
583
600
  }
584
- stream.end();
601
+ this.safeEndStream(stream);
585
602
  }
586
603
 
587
604
  start() {