Skip to content

Commit

Permalink
Abort if trying to use shared pgsql connection from non-main thread
Browse files Browse the repository at this point in the history
Connections cannot be shared between threads, document it.
See #13141
  • Loading branch information
Sandro Santilli committed Jan 19, 2016
1 parent da372c8 commit 670ded3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
5 changes: 5 additions & 0 deletions src/providers/postgres/qgspostgresconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 670ded3

Please sign in to comment.