Skip to content

Commit

Permalink
refactor(repeater): stop sending ping event (#584)
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 8, 2024
1 parent f739b57 commit c22dc2b
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions src/Repeater/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const enum SocketEvents {
ERROR = 'error',
UPDATE_AVAILABLE = 'update-available',
SCRIPT_UPDATED = 'scripts-updated',
PING = 'ping',
REQUEST = 'request'
}

Expand Down Expand Up @@ -81,13 +80,11 @@ interface SocketEmitEventMap {
runtime?: DeploymentRuntime
) => void;
[SocketEvents.UNDEPLOY]: () => void;
[SocketEvents.PING]: () => void;
}

@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;
Expand All @@ -97,7 +94,6 @@ export class DefaultRepeaterServer implements RepeaterServer {
HandlerFunction
>();
private latestReconnectionError?: Error;
private pingTimer?: Timer;
private connectionTimer?: Timer;
private _socket?: Socket<SocketListeningEventMap, SocketEmitEventMap>;
private connectionAttempts = 0;
Expand All @@ -120,7 +116,6 @@ export class DefaultRepeaterServer implements RepeaterServer {

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

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

this.createPingTimer();

return result;
}

Expand Down Expand Up @@ -373,8 +366,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 @@ -394,19 +385,4 @@ export class DefaultRepeaterServer implements RepeaterServer {
);
logger.error(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 c22dc2b

Please sign in to comment.