Unverified Commit 1b1ca027 authored by gitfortian's avatar gitfortian Committed by GitHub

[Fix-2872][admin] Fix page shows message "Session dose not exists" when backend restart (#2876)

* fix multi user login with the same token value insert error * fix multi user login with the same token value insert error * 代码格式化 * use reentrant lock to instead synchronized * fix session dose not exists error * code format --------- Co-authored-by: tianxy105 <lucas123.COM>
parent 416684a2
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.context; package org.dinky.context;
import org.dinky.data.constant.SseConstant;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.vo.SseDataVo; import org.dinky.data.vo.SseDataVo;
...@@ -51,7 +52,10 @@ public class SseSessionContextHolder { ...@@ -51,7 +52,10 @@ public class SseSessionContextHolder {
if (exists(sessionId)) { if (exists(sessionId)) {
return sessionMap.get(sessionId).updateTopics(topics); return sessionMap.get(sessionId).updateTopics(topics);
} else { } else {
throw new BusException("Session does not exist"); HashSet<String> reconnectMessage = new HashSet<>(1);
reconnectMessage.add(SseConstant.SSE_SESSION_INVALID);
log.warn("session id is invalid");
return reconnectMessage;
} }
} }
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.constant;
public class SseConstant {
/**
* Sse label for front to reconnect session
*/
public static final String SSE_SESSION_INVALID = "SESSION_INVALID";
}
...@@ -92,7 +92,8 @@ export default class LineageDagExt extends LineageDag { ...@@ -92,7 +92,8 @@ export default class LineageDagExt extends LineageDag {
edges: result.edges edges: result.edges
}; };
setTimeout(() => { setTimeout(
() => {
let tmpEdges = result.edges; let tmpEdges = result.edges;
result.edges = []; result.edges = [];
// this.canvas.wrapper.style.visibility = 'hidden'; // this.canvas.wrapper.style.visibility = 'hidden';
...@@ -140,6 +141,8 @@ export default class LineageDagExt extends LineageDag { ...@@ -140,6 +141,8 @@ export default class LineageDagExt extends LineageDag {
this.canvas.on('system.canvas.click', () => { this.canvas.on('system.canvas.click', () => {
this.canvas.unfocus(); this.canvas.unfocus();
}); });
}, _.get(this.props, 'config.delayDraw', 0)); },
_.get(this.props, 'config.delayDraw', 0)
);
} }
} }
...@@ -22,6 +22,7 @@ import { ErrorMessage } from '@/utils/messages'; ...@@ -22,6 +22,7 @@ import { ErrorMessage } from '@/utils/messages';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
const session_invalid_label = 'SESSION_INVALID';
export type SseData = { export type SseData = {
topic: string; topic: string;
data: any; data: any;
...@@ -40,7 +41,13 @@ export default () => { ...@@ -40,7 +41,13 @@ export default () => {
const topics: string[] = []; const topics: string[] = [];
subscriberRef.current.forEach((sub) => topics.push(...sub.topic)); subscriberRef.current.forEach((sub) => topics.push(...sub.topic));
const para = { sessionKey: uuidRef.current, topics: topics }; const para = { sessionKey: uuidRef.current, topics: topics };
await postAll('api/sse/subscribeTopic', para).catch((e) => ErrorMessage(e)); await postAll('api/sse/subscribeTopic', para)
.then((res: any) => {
if (res.data.length === 1 && res.data[0] === session_invalid_label) {
reconnectSse();
}
})
.catch((e) => ErrorMessage(e));
}; };
const reconnectSse = () => { const reconnectSse = () => {
const sseUrl = '/api/sse/connect?sessionKey=' + uuidRef.current; const sseUrl = '/api/sse/connect?sessionKey=' + uuidRef.current;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment