Skip to content

Commit

Permalink
Merge pull request #46049 from mhugent/ogr_shared_ds_multithreading
Browse files Browse the repository at this point in the history
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 345dbd6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/core/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -124,7 +129,6 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrFeatureSource *source, bool
}
}
}
QMutexLocker locker( mSharedDS ? &mSharedDS->mutex() : nullptr );

if ( mRequest.destinationCrs().isValid() && mRequest.destinationCrs() != mSource->mCrs )
{
Expand Down Expand Up @@ -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" ) )

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

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

if ( mClosed || !mOgrLayer )
return false;

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

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

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

mClosed = true;



return true;
}

Expand Down

0 comments on commit 345dbd6

Please sign in to comment.