Skip to content
Permalink
Browse files

Abort if trying to use shared pgsql connection from non-main thread

Connections cannot be shared between threads, document it.
See #13141
  • Loading branch information
Sandro Santilli
Sandro Santilli committed Jan 19, 2016
1 parent da372c8 commit 670ded3d0622811f8e0ba50b3f3fd5e783742044
Showing with 9 additions and 0 deletions.
  1. +4 −0 src/providers/postgres/qgspostgresconn.cpp
  2. +5 −0 src/providers/postgres/qgspostgresconn.h
@@ -148,6 +148,10 @@ QgsPostgresConn *QgsPostgresConn::connectDb( QString conninfo, bool readonly, bo

if ( shared )
{
// sharing connection between threads is not safe
// See http://hub.qgis.org/issues/13141
Q_ASSERT( QApplication::instance()->thread() == QThread::currentThread() );

if ( connections.contains( conninfo ) )
{
QgsDebugMsg( QString( "Using cached connection for %1" ).arg( conninfo ) );
@@ -183,6 +183,11 @@ class QgsPostgresConn : public QObject
Q_OBJECT

public:
/*
* @param shared allow using a shared connection. Should never be
* called from a thread other than the main one.
* An assertion guards against such programmatic error.
*/
static QgsPostgresConn *connectDb( QString connInfo, bool readOnly, bool shared = true, bool transaction = false );

void ref() { ++mRef; }

0 comments on commit 670ded3

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