Unverified Commit 81eee7c5 authored by luoshangjie's avatar luoshangjie Committed by GitHub

[Fix] Fix the issue of 'Write end dead' (#3671)

parent 1fa08d68
...@@ -29,6 +29,7 @@ import org.dinky.utils.CloseUtil; ...@@ -29,6 +29,7 @@ import org.dinky.utils.CloseUtil;
import org.dinky.utils.FragmentVariableUtils; import org.dinky.utils.FragmentVariableUtils;
import org.dinky.utils.JsonUtils; import org.dinky.utils.JsonUtils;
import org.dinky.utils.LogUtil; import org.dinky.utils.LogUtil;
import org.dinky.utils.SqlUtil;
import java.io.IOException; import java.io.IOException;
import java.io.PipedInputStream; import java.io.PipedInputStream;
...@@ -70,7 +71,7 @@ public class SqlGatewayWsContext { ...@@ -70,7 +71,7 @@ public class SqlGatewayWsContext {
private PipedInputStream in2web; private PipedInputStream in2web;
private long lastHeartTime = System.currentTimeMillis(); private long lastHeartTime = System.currentTimeMillis();
private boolean isRunning = true; private volatile boolean isRunning = true;
private static String url; private static String url;
private static String username; private static String username;
...@@ -103,15 +104,23 @@ public class SqlGatewayWsContext { ...@@ -103,15 +104,23 @@ public class SqlGatewayWsContext {
} }
}); });
executor.execute(() -> { executor.execute(() -> {
try { while (isRunning) {
int data; try {
byte[] bytes = new byte[1024]; int data;
while ((data = in2web.read(bytes)) != -1) { byte[] bytes = new byte[1024];
session.getBasicRemote().sendBinary(ByteBuffer.wrap(bytes, 0, data)); while ((data = in2web.read(bytes)) != -1) {
session.getBasicRemote().sendBinary(ByteBuffer.wrap(bytes, 0, data));
}
log.info("Sql Client Read Terminal Thread Closed :" + options.getConnectAddress());
onClose();
} catch (IOException e) {
log.error("sql client receive error", e);
try {
Thread.sleep(1000);
} catch (InterruptedException interruptedException) {
log.error("Sql Client Thread Interrupted Error: ", e);
}
} }
log.info("Sql Client Read Terminal Thread Closed :" + options.getConnectAddress());
} catch (IOException e) {
log.error("sql client receive error", e);
} }
}); });
} catch (Exception e) { } catch (Exception e) {
...@@ -157,13 +166,14 @@ public class SqlGatewayWsContext { ...@@ -157,13 +166,14 @@ public class SqlGatewayWsContext {
VariableManager variableManager = new VariableManager(); VariableManager variableManager = new VariableManager();
variableManager.registerVariable(variableMap); variableManager.registerVariable(variableMap);
String initSql = URLDecoder.decode(getParameter("initSql"), "UTF-8"); String initSql = URLDecoder.decode(getParameter("initSql"), "UTF-8");
String parsedSql = variableManager.parseVariable(initSql); initSql = SqlUtil.removeNote(initSql);
initSql = variableManager.parseVariable(initSql);
SqlClientOptions options = SqlClientOptions.builder() SqlClientOptions options = SqlClientOptions.builder()
.mode(SqlCliMode.fromString(getParameter("mode", true))) .mode(SqlCliMode.fromString(getParameter("mode", true)))
.sessionId(getParameter("sessionId")) .sessionId(getParameter("sessionId"))
.connectAddress(getParameter("connectAddress", true)) .connectAddress(getParameter("connectAddress", true))
.initSql(parsedSql) .initSql(initSql)
.historyFilePath("./tmp/flink-sql-history/history") .historyFilePath("./tmp/flink-sql-history/history")
.terminalSize(size) .terminalSize(size)
.build(); .build();
......
...@@ -199,6 +199,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -199,6 +199,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
type: TabsPageType.terminal type: TabsPageType.terminal
} }
}); });
dispatch({
type: STUDIO_MODEL.updateSelectRightKey,
payload: ''
});
}; };
const currentTabName = LeftMenuKey.PROJECT_KEY; const currentTabName = LeftMenuKey.PROJECT_KEY;
const btnEvent = [...BtnRoute[currentTabName]]; const btnEvent = [...BtnRoute[currentTabName]];
......
...@@ -69,7 +69,7 @@ const TerminalContent: React.FC<TermProps> = (props) => { ...@@ -69,7 +69,7 @@ const TerminalContent: React.FC<TermProps> = (props) => {
const termCols = term.cols; const termCols = term.cols;
const termRows = term.rows; const termRows = term.rows;
const params = `mode=${mode}&cols=${termCols}&rows=${termRows}&sessionId=${sessionId}&initSql=${encodeURIComponent(initSql ? initSql : '')}&connectAddress=${connectAddress}`; const params = `mode=${mode}&cols=${termCols}&rows=${termRows}&sessionId=${sessionId}&initSql=${encodeURIComponent(initSql ?? '')}&connectAddress=${connectAddress}`;
ws = new WebSocket(`${wsUrl}/?${params}`); ws = new WebSocket(`${wsUrl}/?${params}`);
...@@ -122,7 +122,7 @@ const TerminalContent: React.FC<TermProps> = (props) => { ...@@ -122,7 +122,7 @@ const TerminalContent: React.FC<TermProps> = (props) => {
// rendererType: "canvas", //渲染类型 // rendererType: "canvas", //渲染类型
// cols: this.cols,// 设置之后会输入多行之后覆盖现象 // cols: this.cols,// 设置之后会输入多行之后覆盖现象
// convertEol: true, //启用时,光标将设置为下一行的开头 // convertEol: true, //启用时,光标将设置为下一行的开头
scrollback: 10, //终端中的回滚量 scrollback: 1000, //终端中的回滚量
fontSize: fontSize, //字体大小 fontSize: fontSize, //字体大小
// disableStdin: false, //是否应禁用输入。 // disableStdin: false, //是否应禁用输入。
// cursorStyle: "block", //光标样式 // cursorStyle: "block", //光标样式
......
...@@ -116,7 +116,7 @@ const MiddleContainer = (props: any) => { ...@@ -116,7 +116,7 @@ const MiddleContainer = (props: any) => {
}; };
const updateActiveKey = (item: TabsItemType) => { const updateActiveKey = (item: TabsItemType) => {
const { key, label, subType } = item; const { key, label, subType, type } = item;
if (key === activeKey) { if (key === activeKey) {
return; return;
} }
...@@ -133,7 +133,10 @@ const MiddleContainer = (props: any) => { ...@@ -133,7 +133,10 @@ const MiddleContainer = (props: any) => {
// 根据 作业类型渲染 右侧选中菜单 key // 根据 作业类型渲染 右侧选中菜单 key
dispatch({ dispatch({
type: STUDIO_MODEL.updateSelectRightKey, type: STUDIO_MODEL.updateSelectRightKey,
payload: getRightSelectKeyFromNodeClickJobType(subType ?? '') payload:
type?.toLowerCase() === TabsPageType.terminal
? ''
: getRightSelectKeyFromNodeClickJobType(subType ?? '')
}); });
// 这里如果加此项功能和定位功能重复 , 暂时注释 // 这里如果加此项功能和定位功能重复 , 暂时注释
......
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