-
Notifications
You must be signed in to change notification settings - Fork 54
fix: resolve potential crash and resource management issues in network module #551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ NetManagerThreadPrivate::NetManagerThreadPrivate() | |
| , m_netCheckAvailable(false) | ||
| , m_isSleeping(false) | ||
| , m_showPageTimer(nullptr) | ||
| , m_vpnStateUpdateTimer(nullptr) | ||
| , m_supportWireless(false) | ||
| { | ||
| moveToThread(m_thread); | ||
|
|
@@ -106,12 +107,15 @@ NetManagerThreadPrivate::NetManagerThreadPrivate() | |
|
|
||
| NetManagerThreadPrivate::~NetManagerThreadPrivate() | ||
| { | ||
| // 先断开所有信号,防止析构期间再有新任务(如singleShot)入队 | ||
| disconnect(); | ||
| m_thread->quit(); | ||
| m_thread->wait(QDeadlineTimer(200)); | ||
| // 增大等待时间至1000ms,避免50ms定时器回调等正在执行的任务被terminate强杀 | ||
| m_thread->wait(QDeadlineTimer(1000)); | ||
| if (m_thread->isRunning()) { | ||
| m_thread->terminate(); | ||
| } | ||
| m_thread->wait(QDeadlineTimer(200)); | ||
| m_thread->wait(QDeadlineTimer(500)); | ||
| delete m_thread; | ||
| } | ||
|
|
||
|
|
@@ -416,6 +420,9 @@ void NetManagerThreadPrivate::doInit() | |
| } | ||
| Q_EMIT itemAdded("Root", vpnControlItem); | ||
|
|
||
| m_vpnStateUpdateTimer = new QTimer(this); | ||
| m_vpnStateUpdateTimer->setSingleShot(true); | ||
| m_vpnStateUpdateTimer->setInterval(55); | ||
| auto updateVPNConnectionState = [this]() { | ||
| auto itemList = NetworkController::instance()->vpnController()->items(); | ||
| NetType::NetDeviceStatus state = NetType::DS_Disconnected; | ||
|
|
@@ -431,8 +438,10 @@ void NetManagerThreadPrivate::doInit() | |
| } | ||
| Q_EMIT dataChanged(DataChanged::VPNConnectionStateChanged, "NetVPNControlItem", QVariant::fromValue(state)); | ||
| }; | ||
| auto vpnConnectionStateChanged = [this, updateVPNConnectionState] { | ||
| QTimer::singleShot(50, this, updateVPNConnectionState); | ||
| connect(m_vpnStateUpdateTimer, &QTimer::timeout, this, updateVPNConnectionState); | ||
| auto vpnConnectionStateChanged = [this] { | ||
| // 使用成员定时器,重复触发时自动重置计时,防止多次触发累积 | ||
| m_vpnStateUpdateTimer->start(); | ||
| }; | ||
|
|
||
| auto vpnItemChanged = [this, vpnConnectionStateChanged] { | ||
|
|
@@ -596,6 +605,11 @@ void NetManagerThreadPrivate::clearData() | |
| delete m_autoScanTimer; | ||
| m_autoScanTimer = nullptr; | ||
| } | ||
| if (m_vpnStateUpdateTimer) { | ||
| m_vpnStateUpdateTimer->stop(); | ||
| delete m_vpnStateUpdateTimer; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议用deleteLater
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| m_vpnStateUpdateTimer = nullptr; | ||
| } | ||
| if (m_secretAgent) { | ||
| delete m_secretAgent; | ||
| m_secretAgent = nullptr; | ||
|
|
||
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
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
Oops, something went wrong.
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.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
控制中心已有55的定时器,改为54、56这种
//设置kwin接口后, 等待55ms给kwin反应,根据isEffectLoaded返回值确定真实状态
QTimer::singleShot(55, this, [this] {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
时间算了吧,测试崩溃的时候的控制中心已经改了,说明不是控制中心那些更改的问题,