Skip to content

Commit

Permalink
fix hanging connections leading to crash in blocking netwotk request,…
Browse files Browse the repository at this point in the history
… analogous to fixed ssl-error-request's hanging connections
  • Loading branch information
notguiltyspark committed Jan 19, 2025
1 parent c47bb84 commit 595bce2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/core/network/qgsblockingnetworkrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -229,6 +235,13 @@ 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();

// 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 )
Expand Down

0 comments on commit 595bce2

Please sign in to comment.