From 7c2243a59aa6fb8e45292fdbe9049e683486014b Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 6 Mar 2025 09:13:21 +0000 Subject: [PATCH] [real-time] log transport and clientId in both directions of serverPing (#24084) GitOrigin-RevId: dabd8db6949498ef1a6252864cef94cd4329e3c0 --- services/real-time/app/js/Router.js | 89 ++++++++++++------- .../connection/connection-manager.ts | 30 ++++++- .../ide-react/connection/types/socket.ts | 10 +++ 3 files changed, 92 insertions(+), 37 deletions(-) diff --git a/services/real-time/app/js/Router.js b/services/real-time/app/js/Router.js index 269c86698f..e99369955f 100644 --- a/services/real-time/app/js/Router.js +++ b/services/real-time/app/js/Router.js @@ -263,43 +263,66 @@ module.exports = Router = { ) } pingTimestamp = Date.now() - client.emit('serverPing', ++pingId, pingTimestamp) + client.emit( + 'serverPing', + ++pingId, + pingTimestamp, + client.transport, + client.id + ) }, SERVER_PING_INTERVAL) : null - client.on('clientPong', function (receivedPingId, sentTimestamp) { - pongId = receivedPingId - const receivedTimestamp = Date.now() - if (receivedPingId !== pingId) { - logger.warn( - { - ...connectionDetails, - receivedPingId, - pingId, - sentTimestamp, - receivedTimestamp, - latency: receivedTimestamp - sentTimestamp, - lastPingTimestamp: pingTimestamp, - }, - 'received pong with wrong counter' - ) - } else if ( - receivedTimestamp - sentTimestamp > - SERVER_PING_LATENCY_THRESHOLD + client.on( + 'clientPong', + function ( + receivedPingId, + sentTimestamp, + serverTransport, + serverSessionId, + clientTransport, + clientSessionId ) { - logger.warn( - { - ...connectionDetails, - receivedPingId, - pingId, - sentTimestamp, - receivedTimestamp, - latency: receivedTimestamp - sentTimestamp, - lastPingTimestamp: pingTimestamp, - }, - 'received pong with high latency' - ) + pongId = receivedPingId + const receivedTimestamp = Date.now() + if ( + receivedPingId !== pingId || + (serverSessionId && serverSessionId !== clientSessionId) + ) { + logger.warn( + { + ...connectionDetails, + receivedPingId, + pingId, + sentTimestamp, + receivedTimestamp, + latency: receivedTimestamp - sentTimestamp, + lastPingTimestamp: pingTimestamp, + serverTransport, + serverSessionId, + clientTransport, + clientSessionId, + }, + 'received pong with wrong counter' + ) + } else if ( + receivedTimestamp - sentTimestamp > + SERVER_PING_LATENCY_THRESHOLD + ) { + logger.warn( + { + ...connectionDetails, + receivedPingId, + pingId, + sentTimestamp, + receivedTimestamp, + latency: receivedTimestamp - sentTimestamp, + lastPingTimestamp: pingTimestamp, + }, + 'received pong with high latency' + ) + } } - }) + ) if (settings.exposeHostname) { client.on('debug.getHostname', function (callback) { diff --git a/services/web/frontend/js/features/ide-react/connection/connection-manager.ts b/services/web/frontend/js/features/ide-react/connection/connection-manager.ts index 36eb5a04e3..1402a983ce 100644 --- a/services/web/frontend/js/features/ide-react/connection/connection-manager.ts +++ b/services/web/frontend/js/features/ide-react/connection/connection-manager.ts @@ -122,8 +122,15 @@ export class ConnectionManager extends EventTarget { socket.on('connectionRejected', err => this.onConnectionRejected(err)) socket.on('reconnectGracefully', () => this.onReconnectGracefully()) socket.on('forceDisconnect', (_, delay) => this.onForceDisconnect(delay)) - socket.on('serverPing', (counter, timestamp) => - this.sendPingResponse(counter, timestamp) + socket.on( + 'serverPing', + (counter, timestamp, serverTransport, serverSessionId) => + this.sendPingResponse( + counter, + timestamp, + serverTransport, + serverSessionId + ) ) this.tryReconnect() @@ -504,7 +511,22 @@ export class ConnectionManager extends EventTarget { this.externalHeartbeat.currentStart = t0 } - private sendPingResponse(counter?: number, timestamp?: number) { - this.socket.emit('clientPong', counter, timestamp) + private sendPingResponse( + counter?: number, + timestamp?: number, + serverTransport?: string, + serverSessionId?: string + ) { + const clientTransport = this.socket.socket.transport?.name + const clientSessionId = this.socket.socket.sessionid + this.socket.emit( + 'clientPong', + counter, + timestamp, + serverTransport, + serverSessionId, + clientTransport, + clientSessionId + ) } } diff --git a/services/web/frontend/js/features/ide-react/connection/types/socket.ts b/services/web/frontend/js/features/ide-react/connection/types/socket.ts index 22fe1451cd..75d43cbcf0 100644 --- a/services/web/frontend/js/features/ide-react/connection/types/socket.ts +++ b/services/web/frontend/js/features/ide-react/connection/types/socket.ts @@ -20,6 +20,16 @@ export type Socket = { arg2: any, callback?: (error: Error, ...data: any[]) => void ): void + emit( + event: string, + arg0: any, + arg1: any, + arg2: any, + arg3: any, + arg4: any, + arg5: any, + callback?: (error: Error, ...data: any[]) => void + ): void socket: { connected: boolean connecting: boolean