Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

fix(redis): explorer views share one socket, so SELECT + command is not atomic; folder delete can hit another DB

未关闭
#1,569 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
dart, redis
领域
backend, database

调研方向

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 内容生成。

描述

backend bug connections P1 stability

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
  • DEL frees 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: _keys is not updated and the error hides the partial delete.

Fix

  • Make "select DB + command(s)" atomic: either one socket per (connectionId, role, db) (no SELECT switching at all), or a per-socket async lock with runInDb(db, () async {...}) that issues SELECT inside the lock. One socket per DB is the simpler model; the CLI then gets its own socket and SELECT there only moves the CLI.
  • delMany: UNLINK with fallback to DEL on ERR 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 UNLINK to RedisConnectionTestFake (redis_connection.dart:817).
  • Tests: interleaved SELECT from a second user of the socket during delMany; CLI SELECT 3 followed by an editor action.
主要语言
Dart
星标
23
派生
1
平均合并
31 分钟
30 天内合并 PR
570

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

QueryaHub/Querya-Desktop 的其他 Issue

查看 QueryaHub/Querya-Desktop 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。