Skip to content

Commit c2db70b

Browse files
committed
Stop the timer when the reply finish
This should fix a few reported and unreported issues with false positive timeout errors. Fixes: #12243 (cherry-picked from ace9d2b)
1 parent 4597d28 commit c2db70b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/core/qgsnetworkaccessmanager.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
212212

213213
emit requestCreated( reply );
214214

215-
// abort request, when network timeout happens
215+
// The timer will call abortRequest slot to abort the connection if needed.
216+
// The timer is stopped by the finished signal and is restarted on downloadProgress and
217+
// uploadProgress.
216218
QTimer *timer = new QTimer( reply );
217219
timer->setObjectName( "timeoutTimer" );
218220
connect( timer, SIGNAL( timeout() ), this, SLOT( abortRequest() ) );
@@ -221,6 +223,8 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
221223

222224
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), timer, SLOT( start() ) );
223225
connect( reply, SIGNAL( uploadProgress( qint64, qint64 ) ), timer, SLOT( start() ) );
226+
connect( reply, SIGNAL( finished( ) ), timer, SLOT( stop( ) ) );
227+
QgsDebugMsgLevel( QString( "Created [reply:%1]" ).arg(( qint64 ) reply, 0, 16 ), 3 );
224228

225229
return reply;
226230
}
@@ -233,16 +237,15 @@ void QgsNetworkAccessManager::abortRequest()
233237
QNetworkReply *reply = qobject_cast<QNetworkReply *>( timer->parent() );
234238
Q_ASSERT( reply );
235239

236-
QgsDebugMsg( QString( "Abort [reply:%1]" ).arg(( qint64 ) reply, 0, 16 ) );
237-
240+
reply->abort();
241+
QgsDebugMsgLevel( QString( "Abort [reply:%1] %2" ).arg(( qint64 ) reply, 0, 16 ).arg( reply->url().toString() ), 3 );
238242
QgsMessageLog::logMessage( tr( "Network request %1 timed out" ).arg( reply->url().toString() ), tr( "Network" ) );
239-
240-
if ( reply->isRunning() )
241-
reply->close();
242-
243+
// Notify the application
243244
emit requestTimedOut( reply );
245+
244246
}
245247

248+
246249
QString QgsNetworkAccessManager::cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl )
247250
{
248251
switch ( theControl )

0 commit comments

Comments
 (0)