Skip to content

fix(ws/cache): fanout 日志锁保护 + rate-limit INCR/EXPIRE 原子化 + 0069 迁移幂等 - #2162

Merged
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-19
Aug 31, 2026
Merged

fix(ws/cache): fanout 日志锁保护 + rate-limit INCR/EXPIRE 原子化 + 0069 迁移幂等#2162
DeliciousBuding merged 1 commit into
masterfrom
chore/cleanup-round-19

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

范围(性能/DB 探索 lane 的 P3 收口,round-19)

来自本轮两个只读探索 lane(性能/并发、数据库/网络)报告的已实锤小项:

  • fanout 数据竞争(F20)ws/fanout.go 丢帧日志无锁读 c.UserID/c.DeviceType,而 SetAuth/Manager.SetAuthc.mu 下写入。新增 Conn.Auth() getter(锁下返回身份快照),热路径改走 getter,消除 race。
  • rate-limit 崩溃窗口(DB 4.2 修正版)CheckRateLimit 原为 INCREXPIRE 两步——两步间进程崩溃会留下无 TTL 的 ratelimit:* 永久键,把调用方永久限流。改单条 Lua 脚本原子执行(保持滑动窗口语义不变),新增 TTL 断言测试。
  • 迁移幂等(DB 1.x):0069 ADD COLUMNADD COLUMN IF NOT EXISTS(与 down 的 IF EXISTS 对齐);0070 头注释文件名 0069→0070 笔误修正。

验证(本地已跑)

  • go vet ./internal/cache/ ./internal/ws/
  • go test ./internal/cache/ -count=1 ✅(含新 TTL 测试)
  • go test ./internal/ws/ -count=1 ✅(含新 Auth getter 测试)
  • git diff --check

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 6a390de9-67d4-4723-8a9f-632f4e1ba27c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- ws/conn.go 新增 Auth() getter(c.mu 下读身份),fanout 丢帧日志改走 getter,消除 SetAuth 写入与热路径读取的数据竞争(-race 易发点 F20)
- cache.CheckRateLimit 改单条 Lua(INCR+EXPIRE 原子),杜绝崩溃窗口遗留无 TTL 永久键→永久限流;新增 TTL 断言测试
- 0069 迁移 ADD COLUMN IF NOT EXISTS 幂等化;0070 头注释文件名笔误修正

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
@DeliciousBuding
DeliciousBuding merged commit 0170825 into master Aug 31, 2026
39 checks passed
@DeliciousBuding
DeliciousBuding deleted the chore/cleanup-round-19 branch August 31, 2026 23:15
DeliciousBuding added a commit that referenced this pull request Sep 1, 2026
缺陷(#2154 Wegener 并发报告 #2162 残留):Manager.Register 先于 SetAuth
暴露连接,服务侧 FindByConnID 之后无锁直读 conn.UserID/DeviceType/DeviceID,
与 SetAuth 在 c.mu 下的写构成数据竞争(派发标记、目标绑定校验、事件重放、
控制面 mismatch 检查、fanout 均受影响)。

修复:
- Conn.Auth() 扩为 (userID, deviceType, deviceID) 三元组快照(c.mu 保护)
- agentcontrol mismatch 检查、agent→dispatchsvc 适配器边界(ConnPort 快照
  源头)、app 事件重放 edgeDeviceID 全部改走 Auth()
- dispatchsvc 内部读的是 ConnPort 值快照(适配器边界已修),无竞态
- handler/ws.go 读点在 SetAuth 之后的 goroutine 链内(happens-after),保持

验证:直读模式修复前 -race 复现 DATA RACE(conn.go:78),修复后 ws 包 +
agentcontrol/agent/dispatchsvc/app 全量 -race 干净,快照一致性断言通过

Co-authored-by: DeliciousBuding <DeliciousBuding@users.noreply.github.com>
Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant