Skip to content

Commit

Permalink
[Spatialite provider] Properly destroy QgsSpatiaLiteConnPool singleto…
Browse files Browse the repository at this point in the history
…n at provider unloading. Should fix frequent crash in PyQgsServerWMS on Travis (fixes #17447)
  • Loading branch information
rouault committed Nov 15, 2017
1 parent 7fa11c8 commit 581d0d3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/providers/spatialite/qgsspatialiteconnpool.cpp
Expand Up @@ -13,11 +13,30 @@
* *
***************************************************************************/

#include <QMutex>
#include <QMutexLocker>

#include "qgsspatialiteconnpool.h"

QgsSpatiaLiteConnPool QgsSpatiaLiteConnPool::sInstance;
QgsSpatiaLiteConnPool *QgsSpatiaLiteConnPool::sInstance = nullptr;

QgsSpatiaLiteConnPool *QgsSpatiaLiteConnPool::instance()
{
return &sInstance;
if ( ! sInstance )
{
static QMutex sMutex;
QMutexLocker locker( &sMutex );
if ( ! sInstance )
{
sInstance = new QgsSpatiaLiteConnPool();
}
}
return sInstance;
}

// static public
void QgsSpatiaLiteConnPool::cleanupInstance()
{
delete sInstance;
sInstance = nullptr;
}
12 changes: 11 additions & 1 deletion src/providers/spatialite/qgsspatialiteconnpool.h
Expand Up @@ -68,9 +68,19 @@ class QgsSpatiaLiteConnPoolGroup : public QObject, public QgsConnectionPoolGroup
//! SpatiaLite connection pool - singleton
class QgsSpatiaLiteConnPool : public QgsConnectionPool<QgsSqliteHandle *, QgsSpatiaLiteConnPoolGroup>
{
static QgsSpatiaLiteConnPool sInstance;
static QgsSpatiaLiteConnPool *sInstance;
public:
static QgsSpatiaLiteConnPool *instance();

// Singleton cleanup
//
// Make sure nobody is using the instance before calling
// this function.
//
// WARNING: concurrent call from multiple threads may result
// in double-free of the instance.
//
static void cleanupInstance();
};


Expand Down
1 change: 1 addition & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -5900,6 +5900,7 @@ QGISEXTERN QString getStyleById( const QString &uri, QString styleId, QString &e

QGISEXTERN void cleanupProvider()
{
QgsSpatiaLiteConnPool::cleanupInstance();
QgsSqliteHandle::closeAll();
}

Expand Down

1 comment on commit 581d0d3

@pblottiere
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rouault! WMS tests seem to be stabilized now 🎉

Please sign in to comment.