mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 19:58:09 +00:00
Ping from server (#5039)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
fe5d787250
commit
3d2b60ac99
@ -89,8 +89,6 @@ class Connection implements ClientConnection {
|
|||||||
readonly onConnect?: (event: ClientConnectEvent) => Promise<void>
|
readonly onConnect?: (event: ClientConnectEvent) => Promise<void>
|
||||||
) {
|
) {
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
||||||
|
|
||||||
if (this.pingResponse !== 0 && Date.now() - this.pingResponse > hangTimeout) {
|
if (this.pingResponse !== 0 && Date.now() - this.pingResponse > hangTimeout) {
|
||||||
// No ping response from server.
|
// No ping response from server.
|
||||||
const s = this.websocket
|
const s = this.websocket
|
||||||
@ -108,6 +106,7 @@ class Connection implements ClientConnection {
|
|||||||
this.websocket = null
|
this.websocket = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
void this.sendRequest({ method: 'ping', params: [] }).then(() => {
|
void this.sendRequest({ method: 'ping', params: [] }).then(() => {
|
||||||
this.pingResponse = Date.now()
|
this.pingResponse = Date.now()
|
||||||
})
|
})
|
||||||
@ -229,6 +228,10 @@ class Connection implements ClientConnection {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (resp.result === 'ping') {
|
||||||
|
void this.sendRequest({ method: 'ping', params: [] })
|
||||||
|
return
|
||||||
|
}
|
||||||
if (resp.id !== undefined) {
|
if (resp.id !== undefined) {
|
||||||
const promise = this.requests.get(resp.id)
|
const promise = this.requests.get(resp.id)
|
||||||
if (promise === undefined) {
|
if (promise === undefined) {
|
||||||
|
@ -53,6 +53,7 @@ export class ClientSession implements Session {
|
|||||||
useCompression: boolean = true
|
useCompression: boolean = true
|
||||||
useBroadcast: boolean = false
|
useBroadcast: boolean = false
|
||||||
sessionId = ''
|
sessionId = ''
|
||||||
|
lastRequest = 0
|
||||||
|
|
||||||
total: StatisticsElement = { find: 0, tx: 0 }
|
total: StatisticsElement = { find: 0, tx: 0 }
|
||||||
current: StatisticsElement = { find: 0, tx: 0 }
|
current: StatisticsElement = { find: 0, tx: 0 }
|
||||||
@ -75,6 +76,7 @@ export class ClientSession implements Session {
|
|||||||
|
|
||||||
async ping (): Promise<string> {
|
async ping (): Promise<string> {
|
||||||
// console.log('ping')
|
// console.log('ping')
|
||||||
|
this.lastRequest = Date.now()
|
||||||
return 'pong!'
|
return 'pong!'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +122,7 @@ export class ClientSession implements Session {
|
|||||||
query: DocumentQuery<T>,
|
query: DocumentQuery<T>,
|
||||||
options?: FindOptions<T>
|
options?: FindOptions<T>
|
||||||
): Promise<FindResult<T>> {
|
): Promise<FindResult<T>> {
|
||||||
|
this.lastRequest = Date.now()
|
||||||
this.total.find++
|
this.total.find++
|
||||||
this.current.find++
|
this.current.find++
|
||||||
const context = ctx as SessionContext
|
const context = ctx as SessionContext
|
||||||
@ -129,6 +132,7 @@ export class ClientSession implements Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async searchFulltext (ctx: MeasureContext, query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
|
async searchFulltext (ctx: MeasureContext, query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
|
||||||
|
this.lastRequest = Date.now()
|
||||||
const context = ctx as SessionContext
|
const context = ctx as SessionContext
|
||||||
context.userEmail = this.token.email
|
context.userEmail = this.token.email
|
||||||
context.admin = this.token.extra?.admin === 'true'
|
context.admin = this.token.extra?.admin === 'true'
|
||||||
@ -136,6 +140,7 @@ export class ClientSession implements Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async tx (ctx: MeasureContext, tx: Tx): Promise<TxResult> {
|
async tx (ctx: MeasureContext, tx: Tx): Promise<TxResult> {
|
||||||
|
this.lastRequest = Date.now()
|
||||||
this.total.tx++
|
this.total.tx++
|
||||||
this.current.tx++
|
this.current.tx++
|
||||||
const context = ctx as SessionContext
|
const context = ctx as SessionContext
|
||||||
|
@ -142,10 +142,24 @@ class TSessionManager implements SessionManager {
|
|||||||
|
|
||||||
s[1].session.current = { find: 0, tx: 0 }
|
s[1].session.current = { find: 0, tx: 0 }
|
||||||
}
|
}
|
||||||
for (const r of s[1].session.requests.values()) {
|
const now = Date.now()
|
||||||
const ed = Date.now()
|
const diff = now - s[1].session.lastRequest
|
||||||
|
if (diff > 60000) {
|
||||||
|
console.log('session hang, closing...', h[0], s[1].session.getUser())
|
||||||
|
void this.close(s[1].socket, h[1].workspaceId, 1001, 'CLIENT_HANGOUT')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (diff > 20000 && this.ticks % 10 === 0) {
|
||||||
|
void s[1].socket.send(
|
||||||
|
h[1].context,
|
||||||
|
{ result: 'ping' },
|
||||||
|
s[1].session.binaryResponseMode,
|
||||||
|
s[1].session.useCompression
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (ed - r.start > 30000) {
|
for (const r of s[1].session.requests.values()) {
|
||||||
|
if (now - r.start > 30000) {
|
||||||
console.log(h[0], 'request hang found, 30sec', h[0], s[1].session.getUser(), r.params)
|
console.log(h[0], 'request hang found, 30sec', h[0], s[1].session.getUser(), r.params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,6 +276,7 @@ class TSessionManager implements SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const session = this.createSession(token, pipeline)
|
const session = this.createSession(token, pipeline)
|
||||||
|
|
||||||
session.sessionId = sessionId !== undefined && (sessionId ?? '').trim().length > 0 ? sessionId : generateId()
|
session.sessionId = sessionId !== undefined && (sessionId ?? '').trim().length > 0 ? sessionId : generateId()
|
||||||
session.sessionInstanceId = generateId()
|
session.sessionInstanceId = generateId()
|
||||||
this.sessions.set(ws.id, { session, socket: ws })
|
this.sessions.set(ws.id, { session, socket: ws })
|
||||||
@ -367,6 +382,7 @@ class TSessionManager implements SessionManager {
|
|||||||
),
|
),
|
||||||
sessions: new Map(),
|
sessions: new Map(),
|
||||||
upgrade,
|
upgrade,
|
||||||
|
workspaceId: token.workspace,
|
||||||
workspaceName
|
workspaceName
|
||||||
}
|
}
|
||||||
if (LOGGING_ENABLED) console.time(workspaceName)
|
if (LOGGING_ENABLED) console.time(workspaceName)
|
||||||
|
@ -62,6 +62,8 @@ export interface Session {
|
|||||||
mins5: StatisticsElement
|
mins5: StatisticsElement
|
||||||
|
|
||||||
measureCtx?: { ctx: MeasureContext, time: number }
|
measureCtx?: { ctx: MeasureContext, time: number }
|
||||||
|
|
||||||
|
lastRequest: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,6 +119,7 @@ export interface Workspace {
|
|||||||
upgrade: boolean
|
upgrade: boolean
|
||||||
closing?: Promise<void>
|
closing?: Promise<void>
|
||||||
|
|
||||||
|
workspaceId: WorkspaceId
|
||||||
workspaceName: string
|
workspaceName: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user