Skip to content

chore: add lifecycle logging in dispatcher - #288

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
wangrong1069:agent/pms-bug-bot/9ce4ca1cee1b
Oct 21, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
wangrong1069:agent/pms-bug-bot/9ce4ca1cee1b

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

chore: add lifecycle logging in dispatcher

  1. Elevate key resource lifecycle logs from g_debug to g_info in
    event_dispatcher.c: client fd accept/remove, uid hash table
    cleanup, max_users/max_connections_per_user rejections, and
    dispatcher create/free
  2. Elevate g_debug to g_info in event_relay_dispatcher.c: channel
    creation, pruning disconnected channels, max_event_channel limit,
    slow/broken client removal, and dispatcher free
  3. Add g_info logging in event_receiver.c for connect and free;
    elevate recv error from g_debug to g_info
  4. Elevate g_debug to g_info in event_relay_receiver.c: receiver
    created/free lifecycle, and recv error
  5. Add g_info for allow_callers hash table create/free in
    dbus-service.c; enrich SetAllowCaller message with entry count;
    elevate D-Bus object registration from g_debug to g_info
  6. Add g_info in event-relay-dispatcher.c for request enqueue,
    worker-not-running rejection, and dispatcher free

Influence:

  1. Verify daemon starts and stops with info-level lifecycle logs
  2. Connect a client and confirm allow_callers add/remove logs appear
  3. Trigger max_users/max_connections_per_user limits and verify
    rejection logs at info level
  4. Test event channel creation and verify create/destroy logs
  5. Verify no functional behavior changes from log level adjustments

chore: dispatcher 增加生命周期日志

  1. 将 event_dispatcher.c 中关键资源生命周期日志从 g_debug 提升至
    g_info:客户端 fd 接受/移除、uid 哈希表清理、max_users 及
    max_connections_per_user 拒绝、dispatcher 创建/释放
  2. 将 event_relay_dispatcher.c 中 g_debug 提升至 g_info:通道创建、
    清理断开通道、max_event_channel 限制、慢速/断开客户端移除及
    dispatcher 释放
  3. 在 event_receiver.c 中新增 connect 和 free 的 g_info 日志;
    将 recv 错误从 g_debug 提升至 g_info
  4. 将 event_relay_receiver.c 中 g_debug 提升至 g_info:receiver
    创建/释放生命周期及 recv 错误
  5. 在 dbus-service.c 中为 allow_callers 哈希表创建/释放新增 g_info;
    SetAllowCaller 消息增加条目计数;D-Bus 对象注册从 g_debug
    提升至 g_info
  6. 在 event-relay-dispatcher.c 中为请求入队、worker 未运行拒绝
    及 dispatcher 释放新增 g_info 日志

Influence:

  1. 验证守护进程启停时输出 info 级别生命周期日志
  2. 连接客户端并确认 allow_callers 增加/移除日志出现
  3. 触发 max_users/max_connections_per_user 限制并验证 info 级拒绝日志
  4. 测试事件通道创建并验证创建/销毁日志
  5. 验证日志级别调整未导致功能行为变化

PMS: TASK-395961

Summary by Sourcery

Improve daemon observability by surfacing dispatcher, relay, receiver, and D-Bus lifecycle events and operational failures in standard logs.

New Features:

  • Add info-level lifecycle and resource-management logging across dispatchers, receivers, relay components, and D-Bus service operations.
  • Include connection-limit context and allow-caller totals in operational logs.

Enhancements:

  • Increase visibility of client, channel, receiver, dispatcher, and D-Bus lifecycle events, connection rejections, cleanup, and transport failures through higher-severity logging.

Chores:

  • Update ignore rules.

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds info-level observability for dispatcher, relay, receiver, D-Bus, and allow-caller lifecycles, including resource counts, connection identifiers, limit rejections, and request handling, without changing functional behavior.

Sequence diagram for dispatcher and relay lifecycle logging

sequenceDiagram
    participant Client
    participant EventDispatcher
    participant EventRelayDispatcher
    participant ServerRelayDispatcher
    participant EventReceiver

    EventDispatcher->>EventDispatcher: event_dispatcher_new()
    EventDispatcher-->>EventDispatcher: g_info dispatcher created
    Client->>EventDispatcher: connect()
    EventDispatcher-->>EventDispatcher: g_info accepted client fd
    EventDispatcher->>EventRelayDispatcher: get_event_channel()
    EventRelayDispatcher-->>EventRelayDispatcher: g_info channel created
    ServerRelayDispatcher->>ServerRelayDispatcher: get_event_channel()
    ServerRelayDispatcher-->>ServerRelayDispatcher: g_info event channel request enqueued
    EventReceiver->>EventReceiver: event_receiver_new()
    EventReceiver-->>EventReceiver: g_info receiver connected
    EventDispatcher->>EventDispatcher: event_dispatcher_free()
    EventDispatcher-->>EventDispatcher: g_info dispatcher freeing
    EventRelayDispatcher->>EventRelayDispatcher: event_relay_dispatcher_free()
    EventRelayDispatcher-->>EventRelayDispatcher: g_info dispatcher freeing
    EventReceiver->>EventReceiver: event_receiver_free()
    EventReceiver-->>EventReceiver: g_info receiver closing
Loading

Flow diagram for lifecycle limit and cleanup logging

flowchart TD
    A[Client connection accepted] --> B{max_users reached?}
    B -- Yes --> C[g_info max_users rejection]
    B -- No --> D{max_connections_per_user reached?}
    D -- Yes --> E[g_info per-user limit rejection]
    D -- No --> F[g_info accepted client fd]
    F --> G{Disconnected or send failure?}
    G -- Yes --> H[g_info client removal]
    H --> I{No remaining connections for uid?}
    I -- Yes --> J[g_info uid removal from uid_to_clients]
    I -- No --> K[Continue serving]
    G -- No --> K
Loading

Flow diagram for event channel lifecycle logging

flowchart TD
    A["get_event_channel()"] --> B{Worker running?}
    B -- No --> C[g_info worker-not-running rejection]
    B -- Yes --> D{max_event_channel reached?}
    D -- Yes --> E[g_info channel-limit rejection]
    D -- No --> F[g_info event channel created]
    F --> G{Disconnected or slow client?}
    G -- Yes --> H[g_info channel pruning or removal]
    G -- No --> I[Channel remains active]
Loading

File-Level Changes

Change Details Files
Promote dispatcher, receiver, and connection lifecycle and failure diagnostics to info level, while adding contextual counts and resource identifiers.
  • Log client acceptance, removal, disconnect cleanup, UID-table removal, limit rejections, and dispatcher creation/free.
  • Log relay channel creation, pruning, capacity rejection, slow/broken client removal, and dispatcher free.
  • Log receiver connect/create/free events and receive failures.
src/dispatcher/event_dispatcher.c
src/dispatcher/event_receiver.c
src/dispatcher/event_relay_dispatcher.c
src/dispatcher/event_relay_receiver.c
Add visibility into D-Bus service resource lifecycle and allow-caller state.
  • Log allow_callers creation and cleanup with entry counts.
  • Include the current allow_callers count when registering a caller.
  • Promote D-Bus object registration to info level.
src/server/dbus-service.c
Instrument server-side relay dispatcher lifecycle and event-channel request handling.
  • Log dispatcher freeing, worker-not-running rejections, and queued event-channel requests.
src/server/event-relay-dispatcher.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dispatcher/event_receiver.c" line_range="72-73" />
<code_context>

-    if (receiver->sock_fd >= 0)
+    if (receiver->sock_fd >= 0) {
+        g_info("receiver closing connection to %s (fd=%d)",
+               receiver->address ? receiver->address : "(null)", receiver->sock_fd);
         close(receiver->sock_fd);
+    }
</code_context>
<issue_to_address>
**Failed connects look established**

When `socket()` succeeds but `connect()` fails, `event_receiver_new` sends a failed `connect()` through `event_receiver_free`, which logs “receiver closing connection” for the unconnected socket; operators see a false connection-lifecycle event.

Track whether the connection succeeded before logging its closure, or describe the log as closing the socket instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/dispatcher/event_receiver.c Resolved
1. event_dispatcher.c: promote lifecycle logs (client fd accept/remove,
   uid hash table cleanup, max_users/max_connections_per_user rejection,
   dispatcher create) from g_debug to g_message; promote hard errors
   (accept4/getsockopt(SO_PEERCRED) failure, event_path overrun,
   send() non-EAGAIN failure) from g_warning/g_debug to g_critical;
   demote setsockopt(SO_SNDBUF) failure to g_warning
2. event_relay_dispatcher.c: promote channel create/prune/max_event_channel
   limit/slow and broken client removal from g_debug to g_message;
   promote socketpair() and send() hard failures to g_critical; demote
   SO_RCVBUFFORCE/SO_SNDBUFFORCE fallback failures from g_info to
   g_warning, and SO_RCVBUF/SO_SNDBUF fallback failures from g_debug to
   g_warning
3. event_receiver.c: add g_message for receiver connected
4. event_relay_receiver.c: promote receiver created from g_debug to
   g_message; promote system bus connect/GetEventChannel failures and
   recv() error from g_warning/g_debug to g_critical
5. dbus-service.c: enrich SetAllowCaller message with allow_callers
   entry count

Log: refine dispatcher log levels for lifecycle and errors

Influence:
1. Verify daemon starts and stops with message-level lifecycle logs
2. Connect a client and confirm allow_callers add/remove logs appear
3. Trigger max_users/max_connections_per_user limits and verify
   rejection logs at message level
4. Test event channel creation and verify create/destroy logs
5. Verify no functional behavior changes from log level adjustments

chore: 调整 dispatcher 日志级别,区分生命周期与错误

1. event_dispatcher.c:将生命周期日志(客户端 fd 接受/移除、uid
   哈希表清理、max_users/max_connections_per_user 拒绝、dispatcher
   创建)从 g_debug 提升至 g_message;将硬错误(accept4、
   getsockopt(SO_PEERCRED) 失败、event_path 越界、send() 非 EAGAIN
   失败)从 g_warning/g_debug 提升至 g_critical;setsockopt(SO_SNDBUF)
   失败降为 g_warning
2. event_relay_dispatcher.c:将通道创建/清理/max_event_channel 限制/
   慢速与断开客户端移除从 g_debug 提升至 g_message;socketpair() 与
   send() 硬错误提升至 g_critical;SO_RCVBUFFORCE/SO_SNDBUFFORCE 回退
   失败从 g_info 降为 g_warning,SO_RCVBUF/SO_SNDBUF 回退失败从 g_debug
   提升至 g_warning
3. event_receiver.c:新增 receiver 连接成功的 g_message 日志
4. event_relay_receiver.c:将 receiver 创建从 g_debug 提升至 g_message;
   将系统总线连接/GetEventChannel 失败及 recv() 错误从 g_warning/g_debug
   提升至 g_critical
5. dbus-service.c:SetAllowCaller 消息增加 allow_callers 条目计数

Log: 调整 dispatcher 日志级别,区分生命周期与错误

Influence:
1. 验证守护进程启停时输出 message 级别生命周期日志
2. 连接客户端并确认 allow_callers 增加/移除日志出现
3. 触发 max_users/max_connections_per_user 限制并验证 message 级拒绝日志
4. 测试事件通道创建并验证创建/销毁日志
5. 验证日志级别调整未导致功能行为变化

PMS: TASK-395961
@wangrong1069
wangrong1069 force-pushed the agent/pms-bug-bot/9ce4ca1cee1b branch from 26da3f4 to eda1d2b Compare October 21, 2026 06:19
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交旨在为 dispatcher 模块添加生命周期日志,变更内容与 commit 目的完全一致。代码语法正确、逻辑清晰,无安全漏洞,性能无影响。日志级别升级(g_debug→g_message、g_warning→g_critical)整体合理,但部分 _free() 函数缺少 teardown 日志,与对应 _new() 函数新增的日志存在不对称,属于完整性方面的轻微不足。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无语法逻辑问题,代码保持原有逻辑不变,仅添加日志输出。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整,存在轻微完整性不足 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['在 event_receiver_free()、event_relay_receiver_free()、event_relay_dispatcher_free() 中添加 g_message 或 g_info 级别的 teardown 日志,记录 fd 和相关资源信息,与 _new() 函数的创建日志对称', '考虑将 event_relay_receiver_receive() 中 recv() 失败的日志级别从 g_critical 调整为 g_warning,因为 recv() 失败可能是瞬态网络问题,g_critical 可能在某些 GLib 配置下触发 abort 处理程序']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无性能问题,日志添加位置合理,不影响正常流程性能。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全问题,日志内容均为操作元数据,不含敏感信息。']


💡 改进建议代码示例

/* 建议在以下 _free() 函数中补充 teardown 日志以保持生命周期日志完整性 */

/* event_receiver.c - event_receiver_free() */
void event_receiver_free(EventReceiver *receiver)
{
    if (receiver == NULL)
        return;

    g_message("receiver freed (fd=%d, address=%s)", receiver->sock_fd, receiver->address);

    if (receiver->sock_fd >= 0)
        close(receiver->sock_fd);

    g_free(receiver->address);
    g_free(receiver);
}

/* event_relay_receiver.c - event_relay_receiver_free() */
void event_relay_receiver_free(EventRelayReceiver *receiver)
{
    if (receiver == NULL)
        return;

    g_message("relay: receiver freed (fd=%d, protocol_id=%u)",
              receiver->sock_fd, receiver->event_protocol_id);

    if (receiver->sock_fd >= 0)
        close(receiver->sock_fd);

    g_free(receiver);
}

/* event_relay_dispatcher.c - event_relay_dispatcher_free() */
void event_relay_dispatcher_free(EventRelayDispatcher *dispatcher)
{
    if (dispatcher == NULL)
        return;

    guint n = dispatcher->socket_list ? dispatcher->socket_list->len : 0;

    if (dispatcher->socket_list != NULL)
        g_ptr_array_free(dispatcher->socket_list, TRUE);

    g_message("relay: dispatcher freed (closed %u channel(s))", n);
    g_free(dispatcher);
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangrong1069

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit f62d672 into linuxdeepin:develop/snipe Oct 21, 2026
17 checks passed
@wangrong1069
wangrong1069 deleted the agent/pms-bug-bot/9ce4ca1cee1b branch October 21, 2026 06:29
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.

3 participants