Skip to content
Permalink
Browse files
Merge pull request #46049 from mhugent/ogr_shared_ds_multithreading
Fix locking of ogr datasource in case the datasource is shared (trans…
  • Loading branch information
mhugent committed Nov 18, 2021
2 parents 2bc3f51 + a1be5a9 commit 345dbd60934268772f8c655e9c152303f0a22425
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/core/providers/ogr/qgsogrfeatureiterator.cpp
@@ -53,6 +53,11 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
, mSymbolType( QgsSymbol::symbolTypeForGeometryType( QgsWkbTypes::geometryType( source->mWkbType ) ) )
{

if ( mSharedDS )
{
mSharedDS->mutex().lock();
}

/* When inside a transaction for GPKG/SQLite and fetching fid(s) we might be nested inside an outer fetching loop,
* (see GH #39178) so we need to skip all calls that might reset the reading (rewind) to avoid an endless loop in the
* outer fetching iterator that uses the same connection.
@@ -124,7 +129,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
}
}
}
QMutexLocker locker( mSharedDS ? &mSharedDS->mutex() : nullptr );

if ( mRequest.destinationCrs().isValid() && mRequest.destinationCrs() != mSource->mCrs )
{
@@ -372,8 +376,6 @@ void QgsOgrFeatureIterator::setInterruptionChecker( QgsFeedback *interruptionChe

bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
{
QMutexLocker locker( mSharedDS ? &mSharedDS->mutex() : nullptr );

QgsCPLHTTPFetchOverrider oCPLHTTPFetcher( mAuthCfg, mInterruptionChecker );
QgsSetCPLHTTPFetchOverriderInitiatorClass( oCPLHTTPFetcher, QStringLiteral( "QgsOgrFeatureIterator" ) )

@@ -469,8 +471,6 @@ void QgsOgrFeatureIterator::resetReading()

bool QgsOgrFeatureIterator::rewind()
{
QMutexLocker locker( mSharedDS ? &mSharedDS->mutex() : nullptr );

if ( mClosed || !mOgrLayer )
return false;

@@ -487,10 +487,10 @@ bool QgsOgrFeatureIterator::close()
if ( mSharedDS )
{
iteratorClosed();

mOgrLayer = nullptr;
mSharedDS.reset();
mClosed = true;
mSharedDS->mutex().unlock();
mSharedDS.reset();
return true;
}

@@ -525,6 +525,9 @@ bool QgsOgrFeatureIterator::close()
mOgrLayer = nullptr;

mClosed = true;



return true;
}

0 comments on commit 345dbd6

Please sign in to comment.