mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 00:48:25 +00:00
[real-time] log transport and clientId in both directions of serverPing (#24084)
GitOrigin-RevId: dabd8db6949498ef1a6252864cef94cd4329e3c0
This commit is contained in:
parent
27e2adecab
commit
6916e22b09
3 changed files with 92 additions and 37 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue