Repository navigation
fix: send fs_event by actual path length in relay thread - #282
Merged
deepin-bot[bot] merged 1 commit intoOct 13, 2026
Merged
deepin-bot[bot] merged 1 commit into
deepin-bot[bot] merged 1 commit into
Conversation
1. Root cause: relay_thread_func() sent fs_event with fixed sizeof(fs_event) (~4KB) instead of actual path length, wasting bandwidth on zero-padded buffer data 2. Fix: calculate send_len as offsetof(fs_event, path) + strlen(ev->path) + 1 to transmit only the meaningful bytes 3. Impact: SOCK_SEQPACKET preserves message boundaries so receivers get exact bytes sent; no protocol or struct change Influence: 1. Test file event forwarding with short paths (<100 bytes) 2. Test file event forwarding with long paths (near 4096 bytes) 3. Verify multi-client broadcast still works correctly fix: relay线程按实际路径长度发送fs_event 1. 根因:relay_thread_func()使用固定sizeof(fs_event)(约4KB) 发送事件,未按实际路径长度计算,传输大量零填充冗余数据 2. 方案:使用offsetof(fs_event, path)+strlen(ev->path)+1计算 实际发送长度,仅传输有效字节数 3. 影响:SOCK_SEQPACKET保留消息边界,接收端收到字节数等于 发送长度,不改变协议结构体布局 Influence: 1. 测试短路径(<100字节)文件事件转发 2. 测试长路径(接近4096字节)文件事件转发 3. 验证多客户端广播功能正常
|
TAG Bot TAG: 7.1.0 |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
lzwind
approved these changes
Oct 13, 2026
|
[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 |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
|
/retest |
deepin-bot
Bot
merged commit Oct 13, 2026
fb58e39
into
linuxdeepin:develop/snipe
15 of 18 checks passed
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.
Root Cause Analysis
relay_thread_func()insrc/server/event-relay-dispatcher.csendsfs_eventusingsizeof(fs_event)(~4KB) as the send length, regardless of the actual path length. Sincefs_event.pathis a fixedgchar path[4096]buffer, every event transmits ~4KB of zero-padded data even when the actual path is typically 20–200 bytes. The root cause is a parameter selection error at line 82 — the sender passes the full struct size instead of computing the actual byte count needed.Key evidence:
src/server/event-relay-dispatcher.c:82—event_relay_dispatcher_send(d->relay, ev, sizeof(fs_event))uses fixed struct sizesrc/server/fs-event.h:10-16—fs_eventcontainsgchar path[MAX_PATH_LEN](4096 bytes fixed buffer)src/dispatcher/event_relay_dispatcher.c:138—send(fd, buf, len, MSG_NOSIGNAL)directly uses the passedlenFix
Replace
sizeof(fs_event)withoffsetof(fs_event, path) + strlen(ev->path) + 1to transmit only the meaningful bytes (struct header + actual path string including null terminator). Added#include <stddef.h>for theoffsetofmacro.Change Safety Assessment
Code Safety
e8e427c5, PMS BUG-370779) as initial implementation —sizeof(fs_event)was not a previous bug fix, so this change does not revert any historical fixrelay_thread_funcis only called viag_thread_newat line 140; no other callers affectedBusiness Impact Scope
Verification Suggestion
根因分析
src/server/event-relay-dispatcher.c中relay_thread_func()使用sizeof(fs_event)(约4KB)作为发送长度发送fs_event,未根据实际路径长度计算。由于fs_event.path为固定gchar path[4096]缓冲区,每次事件转发都传输大量零填充无效数据,实际路径通常仅 20~200 字节。根因为第82行参数选择错误——发送方传入完整结构体大小而非计算实际需要的字节数。关键证据:
src/server/event-relay-dispatcher.c:82— 使用固定结构体大小发送src/server/fs-event.h:10-16—fs_event含gchar path[4096]固定缓冲区src/dispatcher/event_relay_dispatcher.c:138—send()直接使用传入的len参数修复方案
将
sizeof(fs_event)替换为offsetof(fs_event, path) + strlen(ev->path) + 1,仅传输有效字节(结构体头部 + 实际路径字符串含 null 终止符)。添加#include <stddef.h>以使用offsetof宏。改动安全评估
代码安全评估
e8e427c5,PMS BUG-370779)中引入,sizeof(fs_event)为初始实现非此前 bug 修复产物,本次修改不撤销历史修复relay_thread_func仅通过第140行g_thread_new调用,无其他调用者受影响业务影响范围
验证建议
Summary by Sourcery
Send filesystem events with their actual payload length to avoid transmitting unused path-buffer data.
Bug Fixes:
Enhancements: