SessionId duplicate fix (#4676)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-02-16 21:41:27 +06:00 committed by GitHub
parent 0b06f0bbe7
commit bbe6141eb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View File

@ -205,6 +205,13 @@ class Connection implements ClientConnection {
websocket.onmessage = (event: MessageEvent) => {
const resp = readResponse<any>(event.data, binaryResponse)
if (resp.id === -1 && resp.result === 'hello') {
if ((resp as HelloResponse).alreadyConnected === true) {
this.sessionId = generateId()
if (typeof sessionStorage !== 'undefined') {
sessionStorage.setItem('session.id.' + this.url, this.sessionId)
}
reject(new Error('alreadyConnected'))
}
if ((resp as HelloResponse).binary) {
binaryResponse = true
}

View File

@ -46,6 +46,7 @@ export interface HelloRequest extends Request<any[]> {
export interface HelloResponse extends Response<any> {
binary: boolean
reconnect?: boolean
alreadyConnected?: boolean
}
/**

View File

@ -214,6 +214,17 @@ class TSessionManager implements SessionManager {
let workspace = this.workspaces.get(wsString)
await workspace?.closing
workspace = this.workspaces.get(wsString)
if (sessionId !== undefined && workspace?.sessions?.has(sessionId) === true) {
const helloResponse: HelloResponse = {
id: -1,
result: 'hello',
binary: false,
reconnect: false,
alreadyConnected: true
}
await ws.send(ctx, helloResponse, false, false)
return { error: new Error('Session already exists') }
}
const workspaceName = workspaceInfo.workspaceName ?? workspaceInfo.workspaceUrl ?? workspaceInfo.workspace
if (workspace === undefined) {