Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-threaded usage of QgsNetworkAccessManager #22194

Closed
qgib opened this issue Jan 28, 2016 · 1 comment
Closed

Multi-threaded usage of QgsNetworkAccessManager #22194

qgib opened this issue Jan 28, 2016 · 1 comment
Labels
API API improvement only, no visible user interface changes Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption

Comments

@qgib
Copy link
Contributor

qgib commented Jan 28, 2016

Author Name: Patrick Valsecchi (Patrick Valsecchi)
Original Redmine Issue: 14192
Affected QGIS version: master
Redmine category:network


QgsNetworkAccessManager has a singleton that is used all over the place. The problem is that "all over the place" means from different threads and according to the Qt documentation, QNetworkAccessManager is only reentrant (thread safe only if threads are using different instances).

This problem can easily be proven by adding a check in this method:

QgsNetworkAccessManager* QgsNetworkAccessManager::instance()
{
  static QgsNetworkAccessManager* sInstance( new QgsNetworkAccessManager( QApplication::instance() ) );
  if ( sInstance->thread() != QThread::currentThread() ) {
    abort();
  }
  return sInstance;
}

QGIS will crash quickly when you start it:

#_0  0x00007ffff43ee267 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:55
#_1  0x00007ffff43efeca in __GI_abort () at abort.c:89
#_2  0x00007ffff63970a5 in QgsNetworkAccessManager::instance () at /home/pvalsecchi/src/QGIS/src/core/qgsnetworkaccessmanager.cpp:104
#_3  0x00007fff6bba8c50 in QgsWmsCapabilitiesDownload::downloadCapabilities (this=0x3218810)
    at /home/pvalsecchi/src/QGIS/src/providers/wms/qgswmscapabilities.cpp:1936
#_4  0x00007fff6bba881e in QgsWmsCapabilitiesDownload::downloadCapabilities (this=0x3218810, baseUrl=..., auth=...)
    at /home/pvalsecchi/src/QGIS/src/providers/wms/qgswmscapabilities.cpp:1907
#_5  0x00007fff6bc0ca5f in QgsWMSConnectionItem::createChildren (this=0x3218c20)
    at /home/pvalsecchi/src/QGIS/src/providers/wms/qgswmsdataitems.cpp:69
#_6  0x00007ffff624474c in QgsDataItem::runCreateChildren (item=0x3218c20) at /home/pvalsecchi/src/QGIS/src/core/qgsdataitem.cpp:385
#_7  0x00007ffff6250026 in QtConcurrent::StoredFunctorCall1<QVector<QgsDataItem*>, QVector<QgsDataItem*> (*)(QgsDataItem*), QgsDataItem*>::runFunctor (this=0x3216eb0) at /usr/include/qt4/QtCore/qtconcurrentstoredfunctioncall.h:267
#_8  0x00007ffff624fef5 in QtConcurrent::RunFunctionTask<QVector<QgsDataItem*> >::run (this=0x3216eb0)
    at /usr/include/qt4/QtCore/qtconcurrentrunbase.h:106
#_9  0x00007ffff5a7adba in QThreadPoolThread::run (this=0x1203390) at concurrent/qthreadpool.cpp:108
#_10 0x00007ffff5a87d1c in QThreadPrivate::start (arg=0x1203390) at thread/qthread_unix.cpp:349
#_11 0x00007fffedf1a6aa in start_thread (arg=0x7fff5f5b7700) at pthread_create.c:333
#_12 0x00007ffff44bfeed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

I propose we fix it using a QThreadStorage like that:

QgsNetworkAccessManager* QgsNetworkAccessManager::instance()
{
  static QThreadStorage<QgsNetworkAccessManager> sInstances;
  return &sInstances.localData();
}

And we make the constructor private to force the code using it to go through instance().


Related issue(s): #22382 (relates)
Redmine related issue(s): 14401


@qgib
Copy link
Contributor Author

qgib commented Mar 5, 2016

Author Name: Jürgen Fischer (@jef-n)


Fixed in changeset "2eb82430bbdb02b0789b3ffe80d5b6fd747fa8cc".


  • status_id was changed from Open to Closed

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! API API improvement only, no visible user interface changes Crash/Data Corruption labels May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API improvement only, no visible user interface changes Bug Either a bug report, or a bug fix. Let's hope for the latter! Crash/Data Corruption
Projects
None yet
Development

No branches or pull requests

1 participant