From bd28ac71ac4f50cccdc598c32e3481902683c316 Mon Sep 17 00:00:00 2001 From: notguiltyspark Date: Tue, 14 Jan 2025 22:53:53 +0300 Subject: [PATCH 1/2] fixed wfs-connection triggering ssl-error response leading to crash --- src/providers/wfs/qgsbasenetworkrequest.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/providers/wfs/qgsbasenetworkrequest.cpp b/src/providers/wfs/qgsbasenetworkrequest.cpp index 31a5aa0c3c21..73e4201ff9b0 100644 --- a/src/providers/wfs/qgsbasenetworkrequest.cpp +++ b/src/providers/wfs/qgsbasenetworkrequest.cpp @@ -306,15 +306,22 @@ bool QgsBaseNetworkRequest::issueRequest( QNetworkRequest &request, const QByteA // note that we don't need to handle waking this thread back up - that's done automatically by QgsNetworkAccessManager }; - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection ); - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection ); - + QMetaObject::Connection authRequestConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection ); + QMetaObject::Connection proxyAuthenticationConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection ); #ifndef QT_NO_SSL - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection ); + QMetaObject::Connection sslErrorConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection ); #endif + QEventLoop loop; connect( this, &QgsBaseNetworkRequest::downloadFinished, &loop, &QEventLoop::quit, Qt::DirectConnection ); loop.exec(); + + // event loop exited - need to disconnect as to not leave functor hanging to receive signals in future + disconnect( authRequestConnection ); + disconnect( proxyAuthenticationConnection ); +#ifndef QT_NO_SSL + disconnect( sslErrorConnection ); +#endif } } waitConditionMutex.lock(); From 5bc4fce2d542a83ff9123ee0f3420d4c3e9c3227 Mon Sep 17 00:00:00 2001 From: notguiltyspark Date: Sun, 19 Jan 2025 18:49:29 +0300 Subject: [PATCH 2/2] fix hanging connections leading to crash in blocking netwotk request, analogous to fixed ssl-error-request's hanging connections --- .../network/qgsblockingnetworkrequest.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/network/qgsblockingnetworkrequest.cpp b/src/core/network/qgsblockingnetworkrequest.cpp index c80e28630e9a..a99c945f24b5 100644 --- a/src/core/network/qgsblockingnetworkrequest.cpp +++ b/src/core/network/qgsblockingnetworkrequest.cpp @@ -213,13 +213,19 @@ QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::doRequest( QgsBl // note that we don't need to handle waking this thread back up - that's done automatically by QgsNetworkAccessManager }; + QMetaObject::Connection authRequestConnection; + QMetaObject::Connection proxyAuthenticationConnection; +#ifndef QT_NO_SSL + QMetaObject::Connection sslErrorsConnection; +#endif + if ( requestMadeFromMainThread ) { - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection ); - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection ); + authRequestConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::authRequestOccurred, this, resumeMainThread, Qt::DirectConnection ); + proxyAuthenticationConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::proxyAuthenticationRequired, this, resumeMainThread, Qt::DirectConnection ); #ifndef QT_NO_SSL - connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection ); + sslErrorsConnection = connect( QgsNetworkAccessManager::instance(), &QgsNetworkAccessManager::sslErrorsOccurred, this, resumeMainThread, Qt::DirectConnection ); #endif } QEventLoop loop; @@ -229,6 +235,16 @@ QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::doRequest( QgsBl connect( qApp, &QCoreApplication::aboutToQuit, &loop, &QEventLoop::quit, Qt::DirectConnection ); connect( this, &QgsBlockingNetworkRequest::finished, &loop, &QEventLoop::quit, Qt::DirectConnection ); loop.exec(); + + if ( requestMadeFromMainThread ) + { + // event loop exited - need to disconnect as to not leave functor hanging to receive signals in future + disconnect( authRequestConnection ); + disconnect( proxyAuthenticationConnection ); +#ifndef QT_NO_SSL + disconnect( sslErrorsConnection ); +#endif + } } if ( requestMadeFromMainThread )