Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(redis): close pending pubsub connections on unmount

t8y2ea44730c8a40
diff --git a/apps/desktop/src/components/redis/RedisPubSubPanel.vue b/apps/desktop/src/components/redis/RedisPubSubPanel.vue
index e2239ca355..10e174efdb 100644
--- a/apps/desktop/src/components/redis/RedisPubSubPanel.vue
+++ b/apps/desktop/src/components/redis/RedisPubSubPanel.vue
@@ -34,6 +34,8 @@ let nextId = 0;
let ws: WebSocket | null = null;
const connected = ref(false);
const connecting = ref(false);
+let connectAttempt = 0;
+let disposed = false;
const messagesContainer = ref<HTMLElement | null>(null);
@@ -62,10 +64,15 @@ function addMessage(channel: string, pattern: string | null, payload: string) {
// Connect WebSocket
async function connect() {
- if (ws && ws.readyState === WebSocket.OPEN) return;
+ if (disposed || connecting.value || (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING))) return;
+ const attempt = ++connectAttempt;
connecting.value = true;
try {
const socket = await api.redisPubSubConnect(props.connectionId);
+ if (disposed || attempt !== connectAttempt) {
+ socket.close();
+ return;
+ }
ws = socket;
socket.onopen = () => {
@@ -107,14 +114,17 @@ async function connect() {
connected.value = false;
connecting.value = false;
ws = null;
+ socket.close();
};
} catch (e) {
+ if (attempt !== connectAttempt || disposed) return;
connecting.value = false;
toast(t("redis.pubsubWsConnectFailed", { error: e instanceof Error ? e.message : String(e) }), 5000);
}
}
function disconnect() {
+ connectAttempt += 1;
const socket = ws;
ws = null;
connected.value = false;
@@ -175,6 +185,7 @@ function clearMessages() {
}
onBeforeUnmount(() => {
+ disposed = true;
disconnect();
});
</script>