Skip to content

Commit d4c6ab4

Browse files
committed
GH-5374 check if the LmdbRecordIterator is closed after getting the read lock
1 parent d78001b commit d4c6ab4

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/TripleSourceIterationWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public boolean hasNext() throws QueryEvaluationException {
4848
} catch (QueryEvaluationException e) {
4949
throw e;
5050
} catch (Exception e) {
51-
if (e instanceof InterruptedException) {
52-
Thread.currentThread().interrupt();
53-
}
5451
throw new QueryEvaluationException(e);
5552
}
5653
}
@@ -75,9 +72,6 @@ public T next() throws QueryEvaluationException {
7572
} catch (IllegalStateException | QueryEvaluationException e) {
7673
throw e;
7774
} catch (Exception e) {
78-
if (e instanceof InterruptedException) {
79-
Thread.currentThread().interrupt();
80-
}
8175
throw new QueryEvaluationException(e);
8276
}
8377
}

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/LmdbRecordIterator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.nio.ByteBuffer;
27+
import java.util.NoSuchElementException;
2728
import java.util.concurrent.locks.StampedLock;
2829

2930
import org.eclipse.rdf4j.sail.SailException;
@@ -33,11 +34,14 @@
3334
import org.lwjgl.PointerBuffer;
3435
import org.lwjgl.system.MemoryStack;
3536
import org.lwjgl.util.lmdb.MDBVal;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
3639

3740
/**
3841
* A record iterator that wraps a native LMDB iterator.
3942
*/
4043
class LmdbRecordIterator implements RecordIterator {
44+
private static final Logger log = LoggerFactory.getLogger(LmdbRecordIterator.class);
4145
private final Pool pool;
4246

4347
private final TripleIndex index;
@@ -126,6 +130,11 @@ class LmdbRecordIterator implements RecordIterator {
126130
public long[] next() {
127131
long stamp = txnLock.readLock();
128132
try {
133+
if (closed) {
134+
log.debug("Calling next() on an LmdbRecordIterator that is already closed, returning null");
135+
return null;
136+
}
137+
129138
if (txnRefVersion != txnRef.version()) {
130139
// cursor must be renewed
131140
mdb_cursor_renew(txn, cursor);

0 commit comments

Comments
 (0)