fix(ws/cache): fanout 日志锁保护 + rate-limit INCR/EXPIRE 原子化 + 0069 迁移幂等 - #2162
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
- 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
force-pushed
the
chore/cleanup-round-19
branch
from
August 31, 2026 23:07
fd99ef9 to
e5943b3
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
范围(性能/DB 探索 lane 的 P3 收口,round-19)
来自本轮两个只读探索 lane(性能/并发、数据库/网络)报告的已实锤小项:
ws/fanout.go丢帧日志无锁读c.UserID/c.DeviceType,而SetAuth/Manager.SetAuth在c.mu下写入。新增Conn.Auth()getter(锁下返回身份快照),热路径改走 getter,消除 race。CheckRateLimit原为INCR后EXPIRE两步——两步间进程崩溃会留下无 TTL 的ratelimit:*永久键,把调用方永久限流。改单条 Lua 脚本原子执行(保持滑动窗口语义不变),新增 TTL 断言测试。ADD COLUMN→ADD 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✅