Skip to content

fix: stop XCB event polling after connection failure - #489

Open
yixinshark wants to merge 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/xcb-disconnect-busy-loop
Open

fix: stop XCB event polling after connection failure#489
yixinshark wants to merge 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/xcb-disconnect-busy-loop

Conversation

@yixinshark

@yixinshark yixinshark commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Detect XCB connection failures around event dispatch and flushing.
  • Disable the XCB socket notifier after a disconnect to prevent persistent POLLHUP wakeups and CPU spin.
  • Latch the failure state to avoid repeated warnings from event-loop callbacks.

Test plan

  • cmake --build build --target application-tray -j2
  • git diff --check
  • Diagnosis matched the remote PID 271352: fd 17 repeatedly returned POLLIN|POLLHUP after the X11/XCB peer disconnected.

Summary by Sourcery

Handle X11/XCB connection failures in the application tray event loop to avoid runaway polling after disconnects.

Bug Fixes:

  • Stop dispatching X11 events and flushing when the XCB connection has failed to prevent CPU spin on POLLHUP.
  • Disable the X11 QSocketNotifier when the XCB connection reports an error to avoid persistent event-loop wakeups.

Enhancements:

  • Track X11 connection failure state within the tray utility to suppress repeated warnings from event callbacks.

Detect XCB connection errors before and after event dispatch and flushing. Keep the socket notifier as a member, disable it after the first connection failure, and latch the failed state to prevent repeated wakeups and log flooding.

在事件分发及刷新前后检测 XCB 连接错误。保存 socket notifier,并在首次连接失败后将其禁用,同时锁存失败状态,避免持续唤醒和重复日志。

Log: stop XCB event polling after connection failure

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

Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yixinshark

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

@sourcery-ai

sourcery-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds centralized XCB connection error handling to the tray util, and uses it to early‑out event dispatch and disable the socket notifier once the X11 connection fails, preventing busy‑looping on POLLHUP and repeated warnings.

Sequence diagram for X11 connection failure handling in event dispatch

sequenceDiagram
    participant QSocketNotifier
    participant Util
    participant xcb_connection_has_error

    QSocketNotifier->>Util: QSocketNotifier::activated
    Util->>Util: dispatchEvents(DispatchEventsMode::Poll)
    Util->>Util: handleX11ConnectionError()
    alt [error detected]
        Util->>xcb_connection_has_error: xcb_connection_has_error(m_x11connection)
        Util-->>QSocketNotifier: m_x11EventNotifier->setEnabled(false)
        Util-->>Util: return (early out)
    else [no error]
        Util->>Util: pollEventFunc(...)
        Util->>Util: handleX11ConnectionError()
        Util->>Util: xcb_flush(connection)
        Util->>Util: handleX11ConnectionError()
    end
Loading

File-Level Changes

Change Details Files
Centralize XCB connection failure detection and use it to short‑circuit event dispatch and flushing.
  • Guard dispatchEvents with a latched failure flag and a helper that checks the XCB connection error state before polling events.
  • Invoke the connection error helper after processing queued events and again after xcb_flush, bailing out if a failure is detected.
  • Ensure connection error checks are no‑ops when there is no active XCB connection.
plugins/application-tray/util.cpp
plugins/application-tray/util.h
Disable the X11 QSocketNotifier once the XCB connection fails to avoid repeated wakeups on POLLHUP and suppress repeated warnings.
  • Track the QSocketNotifier instance in a member variable instead of a local, so it can be disabled when the connection fails.
  • Latch the connection failure state in a boolean member to avoid re‑emitting warnings from subsequent event‑loop callbacks.
  • Log a single warning when the connection fails, including the XCB error code, while leaving the notifier disabled thereafter.
plugins/application-tray/util.cpp
plugins/application-tray/util.h

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

}

xcb_flush(connection);
handleX11ConnectionError();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

需要判断这么多次么?

qCWarning(TRAYUTIL, "Attempting to dispatch X11 events with no connection");
return;
}
if (m_x11ConnectionFailed || handleX11ConnectionError()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

m_x11ConnectionFailed 这个在handleX11ConnectionError里已经判断了,上面的connection判断也可以去掉了吧,

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