Skip to content

Commit bbc9478

Browse files
committed
fix: resolve thread freeze caused by network disconnection
Changed the network check logic for CIFS mounts from checking only first mount point to checking all available mount points when determining trash state. Added new method checkAllCIFSBusy() in NetworkUtils to handle this. Previously, when network disconnection occurred while accessing CIFS shares, the system would only check the first mount point, potentially causing the main thread to hang if that mount point was unresponsive. This fix checks all mount points properly and prevents UI freezes. Log: Fixed thread freeze issue when network disconnection occurs during CIFS access Influence: 1. Test trash operations while connected to CIFS/SMB shares 2. Verify application doesn't freeze when network disconnects 3. Check trash state updates correctly after operations 4. Monitor system responsiveness during network interruptions 5. Test with multiple CIFS mount points simultaneously fix: 解决断网导致主线程卡死问题 修改了检查CIFS挂载的网络逻辑,从仅检查第一个挂载点改为检查所有可用挂载点 来确定回收站状态。在NetworkUtils中添加了新的checkAllCIFSBusy()方法来处理 这种情况。 之前当访问CIFS共享时发生网络断开,系统只会检查第一个挂载点,如果该挂载点 无响应可能导致主线程卡死。此修复会正确检查所有挂载点并防止UI冻结。 Log: 修复了访问CIFS时断网导致应用卡死的问题 Influence: 1. 测试连接CIFS/SMB共享时的回收站操作 2. 验证网络断开时应用不会冻结 3. 检查操作后回收站状态是否正确更新 4. 监控网络中断期间系统的响应性 5. 测试同时使用多个CIFS挂载点的情况
1 parent db59761 commit bbc9478

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

src/dfm-base/utils/fileutils.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,8 @@ bool FileUtils::isCdRomDevice(const QUrl &url)
359359

360360
bool FileUtils::trashIsEmpty()
361361
{
362-
const auto &cifsHost = NetworkUtils::cifsMountHostInfo();
363-
if (!cifsHost.isEmpty()) {
364-
const auto &mountPoint = cifsHost.constKeyValueBegin()->first;
365-
if (NetworkUtils::instance()->checkFtpOrSmbBusy(QUrl::fromLocalFile(mountPoint)))
366-
return true;
362+
if (NetworkUtils::instance()->checkAllCIFSBusy()) {
363+
return true;
367364
}
368365

369366
// not use cache, because some times info unreliable, such as watcher inited temporality

src/dfm-base/utils/networkutils.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void NetworkUtils::doAfterCheckNet(const QString &host, const QStringList &ports
8383
watcher->setFuture(QtConcurrent::run([host, ports, msecs]() {
8484
if (ports.isEmpty()) {
8585
qCInfo(logDFMBase) << "Network check skipped: no ports specified for host:" << host;
86-
return true; // skip check if ports are empty.
86+
return true; // skip check if ports are empty.
8787
}
8888

8989
for (const auto &port : ports) {
@@ -167,6 +167,18 @@ bool NetworkUtils::parseIp(const QString &mpt, QString &ip, QStringList &ports)
167167
return false;
168168
}
169169

170+
bool NetworkUtils::checkAllCIFSBusy()
171+
{
172+
const auto &cifsHost = NetworkUtils::cifsMountHostInfo();
173+
for (const auto &mountPoint : cifsHost.keys()) {
174+
if (NetworkUtils::instance()->checkFtpOrSmbBusy(QUrl::fromLocalFile(mountPoint))) {
175+
return true;
176+
}
177+
}
178+
179+
return false;
180+
}
181+
170182
bool NetworkUtils::checkFtpOrSmbBusy(const QUrl &url)
171183
{
172184
QString host;

src/dfm-base/utils/networkutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class NetworkUtils : public QObject
2727
std::function<void(bool)> callback = nullptr, int msecs = 3000);
2828
bool parseIp(const QString &mpt, QString &ip, QString &port);
2929
bool parseIp(const QString &mpt, QString &ip, QStringList &ports);
30+
bool checkAllCIFSBusy();
3031
bool checkFtpOrSmbBusy(const QUrl &url);
3132
// if network mount,get network mount
3233
static QMap<QString, QString> cifsMountHostInfo();

src/plugins/common/dfmplugin-trashcore/events/trashcoreeventsender.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ void TrashCoreEventSender::initTrashWatcher()
4848

4949
bool TrashCoreEventSender::checkAndStartWatcher()
5050
{
51-
const auto &cifsHost = NetworkUtils::cifsMountHostInfo();
52-
if (!cifsHost.isEmpty()) {
53-
const auto &mountPoint = cifsHost.constKeyValueBegin()->first;
54-
if (NetworkUtils::instance()->checkFtpOrSmbBusy(QUrl::fromLocalFile(mountPoint))) {
55-
timer.start();
56-
return false;
57-
}
51+
if (NetworkUtils::instance()->checkAllCIFSBusy()) {
52+
timer.start();
53+
return false;
5854
}
5955
return trashFileWatcher->startWatcher();
6056
}
@@ -66,14 +62,14 @@ TrashCoreEventSender *TrashCoreEventSender::instance()
6662
}
6763

6864
void TrashCoreEventSender::sendTrashStateChangedDel()
69-
{
65+
{
7066
bool actuallyEmpty = FileUtils::trashIsEmpty();
7167
TrashState newState = actuallyEmpty ? TrashState::Empty : TrashState::NotEmpty;
72-
68+
7369
// Only send signal if state actually changed
7470
if (trashState == TrashState::Unknown || newState != trashState) {
7571
trashState = newState;
76-
72+
7773
// Only send signal when trash becomes empty (files deleted)
7874
if (trashState == TrashState::Empty) {
7975
qInfo() << "TrashCore: Trash became empty, sending state changed signal";

0 commit comments

Comments
 (0)