Skip to content
Permalink
Browse files

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)
  • Loading branch information
elpaso committed Aug 12, 2016
1 parent 4597d28 commit c2db70b3e3f584b97f97d8029db0dc4a3a035d6e
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/core/qgsnetworkaccessmanager.cpp
@@ -212,7 +212,9 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op

emit requestCreated( reply );

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

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

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

QgsDebugMsg( QString( "Abort [reply:%1]" ).arg(( qint64 ) reply, 0, 16 ) );

reply->abort();
QgsDebugMsgLevel( QString( "Abort [reply:%1] %2" ).arg(( qint64 ) reply, 0, 16 ).arg( reply->url().toString() ), 3 );
QgsMessageLog::logMessage( tr( "Network request %1 timed out" ).arg( reply->url().toString() ), tr( "Network" ) );

if ( reply->isRunning() )
reply->close();

// Notify the application
emit requestTimedOut( reply );

}


QString QgsNetworkAccessManager::cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl )
{
switch ( theControl )

0 comments on commit c2db70b

Please sign in to comment.
You can’t perform that action at this time.