Skip to content

Commit

Permalink
Merge pull request #60176 from nextgis/fix_wfs_error_connection
Browse files Browse the repository at this point in the history
fixed wfs-connection triggering ssl-error response leading to crash
  • Loading branch information
rouault authored Jan 20, 2025
2 parents 9454608 + 21f031d commit 03f68d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
22 changes: 19 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,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 )
Expand Down
15 changes: 11 additions & 4 deletions src/providers/wfs/qgsbasenetworkrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 03f68d6

Please sign in to comment.