Skip to content

Commit

Permalink
refactor(repeater): stop sending ping event (#217)
Browse files Browse the repository at this point in the history
Ping historically was there to signal over RMQ that repeater is still
connected
Socket.IO implementation has built in mechanism for disconnection
detection https://socket.io/docs/v4/engine-io-protocol/#heartbeat
  • Loading branch information
denis-maiorov-brightsec authored Aug 7, 2024
1 parent e06a01f commit 51440cd
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions packages/repeater/src/lib/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,17 @@ interface SocketListeningEventMap {
interface SocketEmitEventMap {
[SocketEvents.DEPLOY]: (options: DeployCommandOptions) => void;
[SocketEvents.UNDEPLOY]: () => void;
[SocketEvents.PING]: () => void;
}

@scoped(Lifecycle.ContainerScoped)
@injectable()
export class DefaultRepeaterServer implements RepeaterServer {
private readonly MAX_DEPLOYMENT_TIMEOUT = 60_000;
private readonly MAX_PING_INTERVAL = 10_000;
private readonly MAX_RECONNECTION_ATTEMPTS = 20;
private readonly MIN_RECONNECTION_DELAY = 1000;
private readonly MAX_RECONNECTION_DELAY = 86_400_000;

private latestReconnectionError?: Error;
private pingTimer?: Timer;
private connectionTimer?: Timer;
private _socket?: Socket<SocketListeningEventMap, SocketEmitEventMap>;
private connectionAttempts = 0;
Expand Down Expand Up @@ -104,7 +101,6 @@ export class DefaultRepeaterServer implements RepeaterServer {

public disconnect() {
this.events.removeAllListeners();
this.clearPingTimer();
this.clearConnectionTimer();

this._socket?.disconnect();
Expand All @@ -128,8 +124,6 @@ export class DefaultRepeaterServer implements RepeaterServer {
)
]);

this.createPingTimer();

return result;
}

Expand Down Expand Up @@ -336,8 +330,6 @@ export class DefaultRepeaterServer implements RepeaterServer {
};

private handleDisconnect = (reason: string): void => {
this.clearPingTimer();

if (reason !== 'io client disconnect') {
this.events.emit(RepeaterServerEvents.DISCONNECTED);
}
Expand All @@ -356,19 +348,4 @@ export class DefaultRepeaterServer implements RepeaterServer {
);
this.logger.error('An error occurred', error);
}

private createPingTimer() {
this.clearPingTimer();

this.pingTimer = setInterval(
() => this.socket.volatile.emit(SocketEvents.PING),
this.MAX_PING_INTERVAL
).unref();
}

private clearPingTimer() {
if (this.pingTimer) {
clearInterval(this.pingTimer);
}
}
}

0 comments on commit 51440cd

Please sign in to comment.