fix(redis): explorer views share one socket, so SELECT + command is not atomic; folder delete can hit another DB
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with lib/core/database/redis_service.dart and lib/core/database/redis_connection.dart to trace socket sharing and database selection, then read lib/features/redis/redis_keys_view.dart and redis_cli_workspace.dart for the affected operations. Reproduce the interleaving described in the issue and inspect the existing Redis connection tests. Done means database selection and commands cannot interfere across views or the CLI, with regression coverage for both reported cases.
由索引模型根据 Issue 内容生成。
描述
Problem
RedisService.acquire keys sockets by connectionId::role (lib/core/database/redis_service.dart:26). Every Redis explorer for a connection, for any database index, uses the same explorer socket. Views select the database with a separate command before working:
await widget.connection.selectDatabase(widget.database); // SELECT n
await widget.connection.delMany(keys); // DEL ... (several round trips)
SELECT is socket state, and the pair is not atomic. Anything else that runs on the socket between the two awaits changes the database the next command hits.
1. Folder delete can delete keys in another database (data loss)
RedisKeysView._deleteFolder (lib/features/redis/redis_keys_view.dart:218-225) selects the DB once, then delMany (lib/core/database/redis_connection.dart:749-761) sends sequential DEL chunks of 200, awaiting each.
Steps: open db0, load a folder with more than 200 keys, Delete folder, then while it runs click db3 in the tree. The workspace replaces the explorer (ValueKey('redis_<id>_db_3'), workspace_panel.dart:363). The old view is disposed but its delMany loop keeps going (no cancellation). The new view sends SELECT 3 + SCAN on the same socket, and the remaining DEL chunks run in db3, deleting any keys there with the same names.
2. The CLI runs commands in a database other than the one it shows
RedisCliWorkspace tracks _currentDb only when the user types SELECT (redis_cli_workspace.dart:487-490) and sends every other command as is (:512). The key editor and keys view in the same explorer re-select widget.database before each operation. After SELECT 3 in the CLI, opening any key moves the socket back to db0. The CLI prompt still says db3, but the next DEL / FLUSHDB runs in db0.
3. delMany itself
DELfrees large values synchronously and blocks the Redis event loop.UNLINK(Redis >= 4.0) is not used anywhere in the codebase.- Chunks are sent one after another although the class already pipelines in
typesAndTtls. - On a failure midway the UI does not know which keys are gone:
_keysis not updated and the error hides the partial delete.
Fix
- Make "select DB + command(s)" atomic: either one socket per
(connectionId, role, db)(noSELECTswitching at all), or a per-socket async lock withrunInDb(db, () async {...})that issuesSELECTinside the lock. One socket per DB is the simpler model; the CLI then gets its own socket andSELECTthere only moves the CLI. delMany:UNLINKwith fallback toDELonERR unknown command, pipeline the chunks, stop when the owner is disposed (cancel token), return the count/keys actually removed and reload the list on partial failure.- Add
UNLINKtoRedisConnectionTestFake(redis_connection.dart:817). - Tests: interleaved
SELECTfrom a second user of the socket duringdelMany; CLISELECT 3followed by an editor action.
- 主要语言
- Dart
- 星标
- 23
- 派生
- 1
- 平均合并
- 31 分钟
- 30 天内合并 PR
- 570
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
QueryaHub/Querya-Desktop 的其他 Issue
-
enhancement ui
难度 2/5 1-3 小时 新手友好度 78/100
QueryaHub/Querya-Desktop#1689 ·
维护者通常 1 天内回复
-
ui(dialogs): make destructive query and DML preview dialogs adaptive and prevent table name overflow未关闭bug frontend
难度 2/5 1-3 小时 新手友好度 82/100
QueryaHub/Querya-Desktop#1642 ·
维护者通常 1 天内回复
-
bug error-handling settings
难度 1/5 1-3 小时 新手友好度 78/100
QueryaHub/Querya-Desktop#1637 ·
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 88/100
QueryaHub/Querya-Desktop#1636 ·
维护者通常 1 天内回复
-
enhancement marketplace
难度 2/5 1-3 小时 新手友好度 78/100
QueryaHub/Querya-Desktop#1635 ·
维护者通常 1 天内回复
查看 QueryaHub/Querya-Desktop 的全部 Issue
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 65/100
chriskelly/wish-together#36 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
AppFlowy-IO/AppFlowy#9075 ·
-
Paste asks for iOS paste permission because the default context menu ignores SystemContextMenu可能已有人在做 @dorklein 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
maheshj01/searchfield#267 ·
-
难度 2/5 1-3 小时 新手友好度 67/100
-
难度 2/5 1-3 小时 新手友好度 72/100
hajisensai/Fushi#2340 · 2 条评论 ·
维护者通常 1 天内回复