Skip to content

Commit

Permalink
UBERF-7118: Fix upgrade/refresh on reconnect (#5704)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo authored May 30, 2024
1 parent 3e913c9 commit 42d8c45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions server/ws/src/server_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ export function startHttpServer (

if (webSocketData.session instanceof Promise) {
void webSocketData.session.then((s) => {
if ('upgrade' in s || 'error' in s) {
if ('error' in s) {
ctx.error('error', { error: s.error?.message, stack: s.error?.stack })
}
if ('error' in s) {
ctx.error('error', { error: s.error?.message, stack: s.error?.stack })
}
if ('upgrade' in s) {
void cs
.send(ctx, { id: -1, result: { state: 'upgrading', stats: (s as any).upgradeInfo } }, false, false)
.then(() => {
Expand Down
18 changes: 17 additions & 1 deletion server/ws/src/server_u.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export function startUWebsocketServer (
mode: data.payload.extra?.mode,
model: data.payload.extra?.model
}
data.connectionSocket = createWebSocketClientSocket(wrData, ws, data)
const cs = createWebSocketClientSocket(wrData, ws, data)
data.connectionSocket = cs

data.session = sessions.addSession(
ctx,
Expand All @@ -138,6 +139,21 @@ export function startUWebsocketServer (
undefined,
accountsUrl
)

if (data.session instanceof Promise) {
void data.session.then((s) => {
if ('error' in s) {
ctx.error('error', { error: s.error?.message, stack: s.error?.stack })
}
if ('upgrade' in s) {
void cs
.send(ctx, { id: -1, result: { state: 'upgrading', stats: (s as any).upgradeInfo } }, false, false)
.then(() => {
cs.close()
})
}
})
}
},
message: (ws, message, isBinary) => {
const data = ws.getUserData()
Expand Down

0 comments on commit 42d8c45

Please sign in to comment.