Skip to content

Commit

Permalink
fix: avoid undefined usage during shutdown
Browse files Browse the repository at this point in the history
The tunnel announce may still run during shutdown, make sure
to not reference undefined.
  • Loading branch information
fredriklindberg committed Feb 10, 2024
1 parent ce2872a commit 03df487
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 03df487

Please sign in to comment.