Repository navigation
fix(index): remove redundant setsockopt that shrinks receive buffer - #285
Conversation
|
TAG Bot TAG: 7.1.0 |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码变更语法正确,移除 setsockopt 调用块及其错误处理逻辑后,函数控制流保持完整,return fd 语句正常返回。已确认 kReceiveBufSize 常量无其他引用,所有 include 头文件(sys/socket.h、cstring、cerrno)仍被其他代码使用,无遗留未使用依赖。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 移除冗余代码后新增的注释详尽说明了移除原因,包括 SO_RCVBUFFORCE、rmem_max 限制、缓冲区缩小风险等关键技术细节,可维护性良好。无重复代码,无残留调试代码。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 移除冗余的系统调用 setsockopt 略微减少了系统调用开销。更重要的是,该修复确保了服务端通过 SO_RCVBUFFORCE 设置的 8MB 接收缓冲区不会被客户端的 SO_RCVBUF 调用覆盖缩小,避免了在 rmem_max < 8MB 系统上因缓冲区不足导致的 EAGAIN 断连和全量索引重建,显著提升了突发文件操作场景下的性能和稳定性。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 本次变更为纯代码移除操作,未引入新的攻击面。不涉及用户输入处理、文件路径操作、网络通信等安全敏感场景。无命令注入、SQL注入、路径遍历、缓冲区溢出等安全风险。 💡 改进建议代码示例// 修复后的代码(已移除冗余 setsockopt 调用)
int VfsMonitorFileSystemWatcherPrivate::connectDispatcherSocket()
{
// ... 获取 fd 的逻辑 ...
// The dispatcher already sets the receive buffer via SO_RCVBUFFORCE
// (with SO_RCVBUF fallback) on the socketpair fd before passing it
// through D-Bus. Re-issuing SO_RCVBUF here would override that with
// a value capped by rmem_max, potentially *shrinking* the buffer on
// systems where rmem_max < 8 MiB.
return fd;
}本报告由 AI 代码审查工具自动生成 |
|
/retest |
The dispatcher (event_relay_dispatcher.c) already sets the socketpair receive buffer to 8 MiB via SO_RCVBUFFORCE (with SO_RCVBUF fallback) before passing the fd through D-Bus. The client's connectDispatcherSocket() re-issued setsockopt(SO_RCVBUF, 8MB) on the same fd, which overrides the server's setting with a value capped by rmem_max — on systems where rmem_max < 8 MiB (common default 4 MiB) this *shrinks* the buffer from the intended 8 MiB down to rmem_max, negating the server's effort. Remove the redundant setsockopt block and the now-unused kReceiveBufSize constant. The server-side SO_RCVBUFFORCE ensures the 8 MiB buffer survives across the D-Bus fd handoff without client intervention. Log: 移除客户端冗余的 setsockopt(SO_RCVBUF) 调用,防止覆盖服务端 SO_RCVBUFFORCE 设置的 8MB 缓冲区 Influence: 1. connectDispatcherSocket 返回值和控制流不变,调用者无感知 2. 在 rmem_max < 8MB 的系统上,接收缓冲区不再被缩小 3. event_receiver.c 的 setsockopt(SO_RCVBUF) 不受影响(作用于自行创建的 socket) PMS: TASK-395961
1cd7950 to
3611ff3
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wangrong1069 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Root Cause Analysis
The dispatcher (
event_relay_dispatcher.c) already sets the socketpair receive buffer to 8 MiB viaSO_RCVBUFFORCE(withSO_RCVBUFfallback) before passing the fd through D-Bus. The client'sconnectDispatcherSocket()re-issuedsetsockopt(SO_RCVBUF, 8MB)on the same fd, which overrides the server's setting with a value capped byrmem_max— on systems wherermem_max < 8 MiB(common default 4 MiB) this shrinks the buffer from the intended 8 MiB down tormem_max, negating the server's effort. Key evidence:vfsmonitorwatcher.cpp:604-609(redundant client-sidesetsockopt) andevent_relay_dispatcher.c:110-118(server-sideSO_RCVBUFFORCEsetting).Fix
Removed the redundant
setsockopt(SO_RCVBUF)block and the now-unusedkReceiveBufSizeconstant fromconnectDispatcherSocket(). The server-sideSO_RCVBUFFORCEensures the 8 MiB buffer survives across the D-Bus fd handoff without client intervention. Implementation matches the analysis recommendation with no deviation.Change Safety Assessment
Code Safety
setsockoptblock; no change to function signature, return value, or control flow. CallersinitDispatcher()andattemptReconnect()only checkfd < 0and are unaffected.36b42fb5(PMS 370779, enlarge buffers to prevent EAGAIN disconnection). After the D-Bus event relay integration (08f68770), the server already setsSO_RCVBUFFORCE(8MB), making the client call redundant and harmful. This fix better achieves 370779's goal by ensuring the 8 MiB buffer is not shrunk.Business Impact Scope
Affected module: VFS file monitoring — the client receives filesystem change events via the dispatcher socket obtained through D-Bus fd passing. Both initial connection (
initDispatcher) and reconnection (attemptReconnect) paths are affected. Users may experience fewer unexpected disconnections and full-index rebuilds during burst file operations on systems withrmem_max < 8 MiB.Verification Suggestion
Perform burst file operations (30k+ create/delete) and confirm no "event dispatcher connection closed" log or full rebuild trigger. On a system with
sysctl net.core.rmem_max=4194304, verify the receive buffer remains 8 MiB after client connection.根因分析
服务端
event_relay_dispatcher.c在创建 socketpair 时已通过SO_RCVBUFFORCE(含SO_RCVBUFfallback)将接收端缓冲区设为 8MB,再经 D-Bus fd passing 传给客户端。客户端connectDispatcherSocket()获取 fd 后又调用setsockopt(SO_RCVBUF, 8MB),该调用使用受rmem_max限制的SO_RCVBUF而非SO_RCVBUFFORCE,在rmem_max < 8MB的系统上会将缓冲区从 8MB 缩小为rmem_max值,抵消服务端的缓冲区扩大努力。关键证据:vfsmonitorwatcher.cpp:604-609(冗余的客户端 setsockopt)和event_relay_dispatcher.c:110-118(服务端 SO_RCVBUFFORCE 设置)。修复方案
移除
connectDispatcherSocket()中冗余的setsockopt(SO_RCVBUF)调用块及不再使用的kReceiveBufSize常量。服务端SO_RCVBUFFORCE确保的 8MB 缓冲区在 D-Bus fd 传递后无需客户端干预即可保留。实际实现与分析建议一致,无偏离。改动安全评估
代码安全评估
setsockopt代码块,不改变函数签名、返回值或控制流。调用者initDispatcher()和attemptReconnect()仅检查fd < 0,不受影响。36b42fb5(PMS 370779,增大缓冲区防止 EAGAIN 断连)中引入。D-Bus event relay 集成(08f68770)后服务端已通过SO_RCVBUFFORCE(8MB)设置缓冲区,客户端调用变为冗余且有害。本次修复更好地实现了 370779 的目标——确保 8MB 缓冲区不被缩小。业务影响范围
受影响模块:VFS 文件监控——客户端通过 D-Bus fd passing 获取的事件通道 socket 接收文件系统变更事件。初始化连接(
initDispatcher)和断线重连(attemptReconnect)路径均受影响。在rmem_max < 8MB的系统上,用户在大量文件操作时将减少意外断连和全量重建索引的情况。验证建议
执行大量文件操作(3 万+ 创建/删除),确认日志无 "event dispatcher connection closed" 且未触发全量重建。在
sysctl net.core.rmem_max=4194304的系统上,验证客户端连接后接收缓冲区保持 8MB。Summary by Sourcery
Bug Fixes: