Skip to content

fix: prevent X11 RECORD notifier busy loops (2500u3) - #225

Open
yixinshark wants to merge 1 commit into
linuxdeepin:develop/2500u3from
yixinshark:fix/x11-record-notifier-spin-2500u3
Open

yixinshark wants to merge 1 commit into
linuxdeepin:develop/2500u3from
yixinshark:fix/x11-record-notifier-spin-2500u3

Conversation

@yixinshark

@yixinshark yixinshark commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Backport #224 to develop/2500u3.

The shortcut plugin can consume a CPU core when an ordinary X event remains in
the RECORD data connection's Xlib queue. XRecordProcessReplies delegates to
XPending, which stops reading the socket while that queue is nonempty. Drain
ordinary events with XPending/XNextEvent so RECORD replies continue to be processed.

Add regression coverage for pointer-button mapping changes, subsequent input
delivery, and RECORD stop/start. Keep an X client connected throughout the suite
to prevent Xvfb resets between tests. This PR contains one commit with the same
patch as the master PR.

将 #224 的 RECORD 空转修复移植到 develop/2500u3。排空 Xlib 普通事件队列,
恢复 RECORD 数据消费;回归测试覆盖鼠标按钮映射变化、后续输入上报和
监控停止后重启。

Validation:

  • Full project configured and built on Qt 6.8 with Release, BUILD_TESTING=ON, and ENABLE_COVERAGE=OFF.
  • RECORD monitor tests passed in isolated Xvfb: 8 passed, 0 failed, 0 skipped.
  • git diff --check passed.

Pms: TASK-398925
Related: linuxdeepin/developer-center#14213

Summary by Sourcery

Prevent X11 RECORD notifier busy loops by draining queued ordinary events before processing monitored input.

Bug Fixes:

  • Prevent X11 RECORD monitoring from stalling when ordinary X events remain queued, avoiding notifier busy loops and preserving input event delivery.
  • Ensure RECORD monitoring can stop and restart reliably after pointer mapping changes.

Tests:

  • Add regression coverage for pointer mapping changes, continued key and modifier event delivery, and RECORD monitor restart behavior while maintaining a persistent X client during the test suite.

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Drain queued ordinary X events before returning from the RECORD notifier so XRecordProcessReplies can continue reading replies and avoid a busy loop.

  • src/plugin-qt/shortcut/src/backend/x11/modifierkeymonitor.cpp L594-603

Tests

Keep an X client connected throughout the suite and add regression coverage for pointer-mapping changes, continued input delivery, and RECORD stop/start.

  • src/plugin-qt/shortcut/tests/tst_x11recordmonitor.cpp L9-13, L45-58, L221-281 (+2 small edits)

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/plugin-qt/shortcut/src/backend/x11/modifierkeymonitor.cpp" line_range="600-603" />
<code_context>
+    // XRecordProcessReplies() calls XPending(), which does not read the
+    // socket while ordinary X events remain in Xlib's queue. Consume them
+    // so RECORD replies keep flowing and the read notifier can become idle.
+    while (XPending(m_dataDisplay) > 0) {
+        XEvent event;
+        XNextEvent(m_dataDisplay, &event);
+    }
 }

</code_context>
<issue_to_address>
**Recorded input stops arriving**

When the data connection receives RECORD replies after context enablement, `handleEvents()` drains Xlib events but never calls `XRecordProcessReplies()`, so queued RECORD data does not reach `handleRecordedData()`. Subsequent key events stop being reported, and the `EndOfData` callback needed to restart capture cannot run.

Call `XRecordProcessReplies()` from `handleEvents()` to dispatch queued RECORD replies.
</issue_to_address>

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

Comment on lines +600 to +603
while (XPending(m_dataDisplay) > 0) {
XEvent event;
XNextEvent(m_dataDisplay, &event);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Recorded input stops arriving

When the data connection receives RECORD replies after context enablement, handleEvents() drains Xlib events but never calls XRecordProcessReplies(), so queued RECORD data does not reach handleRecordedData(). Subsequent key events stop being reported, and the EndOfData callback needed to restart capture cannot run.

Call XRecordProcessReplies() from handleEvents() to dispatch queued RECORD replies.

Prompt for AI agents
In `src/plugin-qt/shortcut/src/backend/x11/modifierkeymonitor.cpp` at lines 600-603:

**Recorded input stops arriving**

When the data connection receives RECORD replies after context enablement, `handleEvents()` drains Xlib events but never calls `XRecordProcessReplies()`, so queued RECORD data does not reach `handleRecordedData()`. Subsequent key events stop being reported, and the `EndOfData` callback needed to restart capture cannot run.

Call `XRecordProcessReplies()` from `handleEvents()` to dispatch queued RECORD replies.

XRecordProcessReplies delegates to XPending, which stops reading the data
socket when ordinary X events remain in Xlib's queue. A MappingNotify can
therefore stall RECORD replies and keep the socket notifier continuously
active, consuming a CPU core in service-manager.

Consume queued X events so XPending can continue processing RECORD replies.
Add a pointer-mapping regression test covering input delivery and RECORD
restart, and keep an X client connected to prevent Xvfb resets between tests.

XRecordProcessReplies 内部调用 XPending;当 Xlib 队列残留普通 X 事件时,
XPending 不再读取数据 socket。MappingNotify 因而可能阻塞 RECORD 回复,
导致 socket 通知器持续触发,service-manager 单线程持续占满 CPU。

消费队列中的普通 X 事件,让 XPending 继续处理 RECORD 回复。新增鼠标
按钮映射变化的回归测试,验证输入上报和 RECORD 重启;测试期间保持
一个 X 客户端连接,防止 Xvfb 在测试用例之间重置。

Log: prevent X11 RECORD notifier busy loops
PMS: TASK-398925
Change-Id: If5cc0eb52d3b2981154c5196b3e207793e78cb0d
@yixinshark
yixinshark force-pushed the fix/x11-record-notifier-spin-2500u3 branch from ceb8b2b to 3aead6d Compare November 19, 2026 07:36
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, 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

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.2.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #228

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