Skip to content

fix: Implement graceful shutdown process in TransferHelper#687

Merged
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bug
Oct 10, 2025
Merged

fix: Implement graceful shutdown process in TransferHelper#687
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bug

Conversation

@re2zero
Copy link
Copy Markdown
Contributor

@re2zero re2zero commented Sep 30, 2025

Add a graceful shutdown method to the TransferHelper class to ensure proper disconnection of the IPC interface and application exit. This change includes logging for better traceability during the shutdown process and introduces a delay before exiting to allow for signal processing completion.

Log: Implement graceful shutdown process in TransferHelper.
Bug: https://pms.uniontech.com/bug-view-335631.html

Summary by Sourcery

Implement a graceful shutdown process in TransferHelper by introducing a dedicated shutdown method, delaying application exit, and ensuring IPC interface cleanup with enhanced logging.

New Features:

  • Add gracefulShutdown slot in TransferHelper to handle delayed and clean application exit

Bug Fixes:

  • Ensure IPC interface is properly disconnected and cleaned up in both destructor and shutdown methods

Enhancements:

  • Introduce logging across shutdown steps for better traceability
  • Schedule delayed exit with QTimer to allow signal and resource cleanup

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 30, 2025

Reviewer's Guide

This PR introduces a structured graceful shutdown process in TransferHelper by adding a new shutdown slot with staged timers and enhanced IPC cleanup, replacing immediate exits with delayed shutdown scheduling and augmenting the destructor to ensure the IPC interface is properly disconnected and freed, all with detailed logging.

Sequence diagram for the new graceful shutdown process in TransferHelper

sequenceDiagram
participant User
participant TransferHelper
participant QTimer
participant IPCInterface
participant qApp
User->>TransferHelper: buttonClicked()
TransferHelper->>TransferHelper: Schedule gracefulShutdown in 500ms
QTimer->>TransferHelper: gracefulShutdown()
TransferHelper->>IPCInterface: disconnectFromServer()
IPCInterface-->>TransferHelper: IPC disconnected
TransferHelper->>QTimer: Schedule qApp->exit(0) in 100ms
QTimer->>qApp: exit(0)
Loading

Updated class diagram for TransferHelper with graceful shutdown

classDiagram
class TransferHelper {
  +void buttonClicked(QString id, DeviceInfoPointer info)
  +void gracefulShutdown()
  -TransferHelper(QObject *parent = nullptr)
  -~TransferHelper()
}
class TransferHelperPrivate {
  +TransferHelperPrivate(TransferHelper *qq)
  +~TransferHelperPrivate()
  ipcInterface
  backendOk
}
TransferHelper --> TransferHelperPrivate : has-a
TransferHelperPrivate --> IPCInterface : has-a
Loading

File-Level Changes

Change Details Files
Add structured graceful shutdown mechanism with delayed exit
  • Defined gracefulShutdown slot with logging and staged QTimer delays
  • Replaced direct qApp->exit in buttonClicked with a 500ms singleShot to invoke gracefulShutdown
  • Within gracefulShutdown, disconnect IPC interface if enabled and schedule final exit after 100ms
src/lib/cooperation/transfer/helper/transferhelper.cpp
src/lib/cooperation/transfer/helper/transferhelper.h
Enhance destructor to clean up IPC interface under ENABLE_COMPAT
  • Logged entry to TransferHelperPrivate destructor
  • Checked backendOk and disconnected ipcInterface before deletion
  • Deleted ipcInterface, nulled pointer, and logged cleanup completion
src/lib/cooperation/transfer/helper/transferhelper.cpp
Improve logging throughout shutdown and cleanup paths
  • Added DLOG calls at shutdown start, IPC disconnection, and application exit
  • Logged scheduling of graceful shutdown in buttonClicked
  • Logged successful IPC interface cleanup in destructor and shutdown
src/lib/cooperation/transfer/helper/transferhelper.cpp

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

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

## Individual Comments

### Comment 1
<location> `src/lib/cooperation/transfer/helper/transferhelper.cpp:372` </location>
<code_context>
+#endif
+    
+    // Give a small additional delay for cleanup to complete
+    QTimer::singleShot(100, qApp, [this]() {
+        DLOG << "Exiting application after cleanup";
+        qApp->exit(0);
</code_context>

<issue_to_address>
**issue (bug_risk):** Review use of lambda capturing 'this' in QTimer context.

If TransferHelper is destroyed before the timer triggers, this could cause undefined behavior. Use a static lambda or guarantee the object's lifetime until the timer fires.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/lib/cooperation/transfer/helper/transferhelper.cpp Outdated
Add a graceful shutdown method to the TransferHelper class to ensure proper disconnection of the IPC interface and application exit. This change includes logging for better traceability during the shutdown process and introduces a delay before exiting to allow for signal processing completion.

Log: Implement graceful shutdown process in TransferHelper.
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

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

@lzwind lzwind merged commit dc2019e into linuxdeepin:master Oct 10, 2025
14 of 16 checks passed
@re2zero re2zero deleted the bug branch October 10, 2025 05:27
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