Skip to content

Commit

Permalink
Merge pull request #71 from exposr/fix-possibly-undefined-usage
Browse files Browse the repository at this point in the history
fix: avoid undefined usage during shutdown
  • Loading branch information
fredriklindberg authored Feb 10, 2024
2 parents 021a646 + 03df487 commit 56e3368
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/tunnel/tunnel-connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export default class TunnelConnectionManager {
clearTimeout(this.stateRefreshTimer);
this.stateRefreshTimer = undefined;

this.running = false;
this.eventBus?.removeAllListeners();
await this.eventBus?.destroy();
(<any>this.eventBus) = undefined;
this.lastConnection = {};
this.connectedTunnels = {};
this.running = false;
}

private static async disconnectTunnel(tunnelId: string): Promise<void> {
Expand Down Expand Up @@ -200,9 +200,9 @@ export default class TunnelConnectionManager {
const chunk = _tunnelIds.splice(0, batchsize);

const tunnels: Array<TunnelAnnounce> = chunk.map((tunnelId) => {
const state = this.connectedTunnels[tunnelId];
const state = this.connectedTunnels[tunnelId] as (TunnelState | undefined);

const localConnections: Array<TunnelConnectionAnnounce> = state.connections
const localConnections: Array<TunnelConnectionAnnounce> = (state?.connections || [])
.filter((con) => con.local)
.map((con) => {
return {
Expand All @@ -221,6 +221,10 @@ export default class TunnelConnectionManager {
}
});

if (!this.running) {
resolve();
return;
}
await this.eventBus.publish("tunnel:announce", tunnels);
if (_tunnelIds.length > 0) {
setImmediate(processChunk);
Expand Down

0 comments on commit 56e3368

Please sign in to comment.