QueryExecutionFailure: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L10699]

Hi,

Background

We execute some CONSTRUCT queries, using a block of code similar to the below code. We then convert it to a List<Statement> and return it.

    try (Connection connection = getConnection()) {

      GraphQueryResult result = null;
      try {
        connection.begin();
        GraphQuery query = connection.graph(sparql).dataset(dataset);

        result = query.execute();
        connection.commit();
        return new ArrayList<>(result.toGraph());
      } catch (StardogException | QueryExecutionFailure e) {
        log.error(e.toString());
        throw new RuntimeException(e);
      } finally {
        if (result != null) {
          try {
            result.close();
          } catch (QueryExecutionFailure e) {
            log.error(e.toString());
          }
        }
      }
    }

Problem

Some of our CONSTRUCT queries return a large number of triples (e.g., around 500K triples). In these cases, this part of the code return new ArrayList<>(result.toGraph()); or more specifically result.toGraph() throws this error:

com.stardog.stark.query.QueryExecutionFailure: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L23996]

com.stardog.stark.query.QueryExecutionFailure: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L23996]
java.lang.RuntimeException: com.stardog.stark.query.QueryExecutionFailure: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L23996]

at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: com.stardog.stark.query.QueryExecutionFailure: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L23996]
	at app//com.complexible.stardog.protocols.http.client.HttpClientImpl.onParseError(HttpClientImpl.java:408)
	at app//com.complexible.stardog.protocols.http.client.HttpClientImpl.lambda$graph$3(HttpClientImpl.java:344)
	at app//com.complexible.common.rdf.query.IteratorAsGraphQueryResult.hasNext(IteratorAsGraphQueryResult.java:117)
	at app//com.complexible.stardog.api.impl.AbstractConnection$OnCloseQueryResult.hasNext(AbstractConnection.java:785)
	at app//com.complexible.stardog.api.impl.AbstractConnection$ConnectionQueryResult.hasNext(AbstractConnection.java:728)
	at app//com.stardog.stark.query.ClosingSpliterator.forEachRemaining(ClosingSpliterator.java:37)
	at java.base@11.0.18/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at 
	... 91 more
Caused by: com.stardog.stark.io.InvalidRDF: Unexpected end of file [L23996]
	at app//com.stardog.stark.io.ParserContext.error(ParserContext.java:247)
	at app//com.stardog.stark.io.ParserContext.error(ParserContext.java:235)
	at app//com.stardog.stark.io.turtle.TurtleParser.parseURI(TurtleParser.java:545)
	at app//com.stardog.stark.io.turtle.TurtleParser.parseValue(TurtleParser.java:503)
	at app//com.stardog.stark.io.turtle.TurtleParser.parseSubjectResource(TurtleParser.java:355)
	at app//com.stardog.stark.io.turtle.TurtleParser.parseSubject(TurtleParser.java:350)
	at app//com.stardog.stark.io.trig.TrigParser.parseTriples(TrigParser.java:236)
	at app//com.stardog.stark.io.trig.TrigParser.parseGraph(TrigParser.java:164)
	at app//com.stardog.stark.io.trig.TrigParser.parseStatement(TrigParser.java:72)
	at app//com.stardog.stark.io.turtle.TurtleParser.parse(TurtleParser.java:97)
	at app//com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:371)
	at app//com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:329)
	at app//com.complexible.common.rdf.rio.RDFStreamProcessor$ProducerThread.work(RDFStreamProcessor.java:917)
	at app//com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:877)
	at app//com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:866)
	at java.base@11.0.18/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base@11.0.18/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base@11.0.18/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base@11.0.18/java.lang.Thread.run(Thread.java:829)

When we change result.toGraph() to something like

        result = query.execute();
        connection.commit();
        List<Statement> listResults2 = new ArrayList<>();
        AtomicInteger i = new AtomicInteger();
        result.stream().forEach( statement -> {
            System.out.println("i: " + i.get());
          listResults2.add(statement);
          i.getAndIncrement();
            }
        );

After adding around 199K triples to the list, it starts throwing these errors. (please ignore the i values if they're not sequential since we deleted some of them to make the text shorter to copy here)

i: 199059
	at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1477)
	at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1066)
i: 199060
	at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
	at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
	at org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:205)
	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:188)
i: 199061
i: 199062
i: 199063
i: 199064
i: 199065
i: 199066
i: 199529
	at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)

i: 199865
	at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:243)
	at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:159)
	at java.base/java.util.zip.GZIPInputStream.read(GZIPInputStream.java:118)
	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:70)
	at org.apache.commons.io.input.ProxyInputStream.read(ProxyInputStream.java:102)
	at com.google.common.io.CountingInputStream.read(CountingInputStream.java:63)
i: 199866
	at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
	at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292)
	at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351)
i: 199867
i: 199868
i: 199869
i: 199870
i: 199871
i: 199872
i: 199873
i: 199874
	at org.apache.commons.io.input.BOMInputStream.read(BOMInputStream.java:335)
	at org.apache.commons.io.input.BOMInputStream.read(BOMInputStream.java:335)
i: 199875
i: 199876
	at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
i: 199877
i: 199878
	at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
i: 199879
i: 199880
	at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
i: 199881
	at java.base/java.io.InputStreamReader.read(InputStreamReader.java:181)
i: 199882
i: 199883
i: 199884
	at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
i: 199885
i: 199886
	at java.base/java.io.BufferedReader.read(BufferedReader.java:182)
i: 199887
i: 199888
	at java.base/java.io.FilterReader.read(FilterReader.java:65)
i: 199889
i: 199890
	at java.base/java.io.PushbackReader.read(PushbackReader.java:90)
i: 199891
i: 199892
	at com.stardog.stark.io.IOParserContext.readCodePoint(IOParserContext.java:128)
i: 199893
i: 199894
	at com.stardog.stark.io.turtle.TurtleParser.parseURI(TurtleParser.java:539)
i: 199895
i: 199896
i: 199897
	at com.stardog.stark.io.turtle.TurtleParser.parseValue(TurtleParser.java:503)
i: 199898
i: 199899
	at com.stardog.stark.io.turtle.TurtleParser.parseObject(TurtleParser.java:376)
i: 199900
i: 199901
	at com.stardog.stark.io.turtle.TurtleParser.parseObjectList(TurtleParser.java:313)
i: 199902
i: 199903
	at com.stardog.stark.io.turtle.TurtleParser.parsePredicateObjectList(TurtleParser.java:233)
i: 199904
i: 199905
	at com.stardog.stark.io.trig.TrigParser.parseTriples(TrigParser.java:238)
i: 199906
i: 199907
	at com.stardog.stark.io.trig.TrigParser.parseGraph(TrigParser.java:164)
i: 199908
i: 199909
	at com.stardog.stark.io.trig.TrigParser.parseStatement(TrigParser.java:72)
i: 199910
i: 199911
	at com.stardog.stark.io.turtle.TurtleParser.parse(TurtleParser.java:97)
i: 199912
i: 199913
	at com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:371)
i: 199914
i: 199915
	at com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:329)
i: 199916
i: 199917
i: 199918
	at com.complexible.common.rdf.rio.RDFStreamProcessor$ProducerThread.work(RDFStreamProcessor.java:917)
i: 199919
i: 199920
i: 199921
	at com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:877)
i: 199922
i: 199923
	at com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:866)
i: 199924
i: 199925
i: 199926
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
i: 199927
i: 199991
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
i: 199992
i: 199993
i: 199994
i: 199995
i: 199996
i: 199997
i: 199998
i: 199999

and then

com.stardog.stark.query.QueryExecutionFailure: java.lang.RuntimeException: java.net.SocketException: Connection reset

com.stardog.stark.query.QueryExecutionFailure: java.lang.RuntimeException: java.net.SocketException: Connection reset
java.lang.RuntimeException: com.stardog.stark.query.QueryExecutionFailure: java.lang.RuntimeException: java.net.SocketException: Connection reset
Caused by: com.stardog.stark.query.QueryExecutionFailure: java.lang.RuntimeException: java.net.SocketException: Connection reset
	at app//com.complexible.stardog.protocols.http.client.HttpClientImpl.onParseError(HttpClientImpl.java:408)
	at app//com.complexible.stardog.protocols.http.client.HttpClientImpl.lambda$graph$3(HttpClientImpl.java:344)
	at app//com.complexible.common.rdf.query.IteratorAsGraphQueryResult.hasNext(IteratorAsGraphQueryResult.java:117)
	at app//com.complexible.stardog.api.impl.AbstractConnection$OnCloseQueryResult.hasNext(AbstractConnection.java:785)
	at app//com.complexible.stardog.api.impl.AbstractConnection$ConnectionQueryResult.hasNext(AbstractConnection.java:728)
	at app//com.stardog.stark.query.ClosingSpliterator.forEachRemaining(ClosingSpliterator.java:37)
	at java.base@11.0.18/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at 
	... 91 more
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
	at com.complexible.common.rdf.rio.RDFStreamProcessor$ConcurrentLoadManagerImpl$StmtIter.computeNext(RDFStreamProcessor.java:849)
	at com.complexible.common.rdf.rio.RDFStreamProcessor$ConcurrentLoadManagerImpl$StmtIter.computeNext(RDFStreamProcessor.java:786)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
	at com.complexible.common.rdf.impl.StreamStatementIterator.computeNext(StreamStatementIterator.java:77)
	at com.complexible.common.rdf.impl.StreamStatementIterator.computeNext(StreamStatementIterator.java:32)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
	at com.complexible.common.base.CloseableIterator$2.computeNext(CloseableIterator.java:84)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
	at com.complexible.common.rdf.query.IteratorAsGraphQueryResult.hasNext(IteratorAsGraphQueryResult.java:114)
	... 96 more
Caused by: java.net.SocketException: Connection reset
	at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
	at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
	at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:484)
	at java.base/sun.security.ssl.SSLSocketInputRecord.readFully(SSLSocketInputRecord.java:467)
	at java.base/sun.security.ssl.SSLSocketInputRecord.decodeInputRecord(SSLSocketInputRecord.java:243)
	at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:181)
	at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:111)
	at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1510)
	at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1477)
	at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1066)
	at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
	at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
	at org.apache.http.impl.io.SessionInputBufferImpl.read(SessionInputBufferImpl.java:205)
	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:188)
	at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)
	at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:243)
	at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:159)
	at java.base/java.util.zip.GZIPInputStream.read(GZIPInputStream.java:118)
	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:70)
	at org.apache.commons.io.input.ProxyInputStream.read(ProxyInputStream.java:102)
	at com.google.common.io.CountingInputStream.read(CountingInputStream.java:63)
	at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
	at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292)
	at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351)
	at org.apache.commons.io.input.BOMInputStream.read(BOMInputStream.java:335)
	at org.apache.commons.io.input.BOMInputStream.read(BOMInputStream.java:335)
	at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
	at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
	at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.base/java.io.InputStreamReader.read(InputStreamReader.java:181)
	at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
	at java.base/java.io.BufferedReader.read(BufferedReader.java:182)
	at java.base/java.io.FilterReader.read(FilterReader.java:65)
	at java.base/java.io.PushbackReader.read(PushbackReader.java:90)
	at com.stardog.stark.io.IOParserContext.readCodePoint(IOParserContext.java:128)
	at com.stardog.stark.io.turtle.TurtleParser.parseURI(TurtleParser.java:539)
	at com.stardog.stark.io.turtle.TurtleParser.parseValue(TurtleParser.java:503)
	at com.stardog.stark.io.turtle.TurtleParser.parseObject(TurtleParser.java:376)
	at com.stardog.stark.io.turtle.TurtleParser.parseObjectList(TurtleParser.java:313)
	at com.stardog.stark.io.turtle.TurtleParser.parsePredicateObjectList(TurtleParser.java:233)
	at com.stardog.stark.io.trig.TrigParser.parseTriples(TrigParser.java:238)
	at com.stardog.stark.io.trig.TrigParser.parseGraph(TrigParser.java:164)
	at com.stardog.stark.io.trig.TrigParser.parseStatement(TrigParser.java:72)
	at com.stardog.stark.io.turtle.TurtleParser.parse(TurtleParser.java:97)
	at com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:371)
	at com.complexible.common.rdf.rio.RDFStreamBuilder$RDFAbstractStream.parse(RDFStreamBuilder.java:329)
	at com.complexible.common.rdf.rio.RDFStreamProcessor$ProducerThread.work(RDFStreamProcessor.java:917)
	at com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:877)
	at com.complexible.common.rdf.rio.RDFStreamProcessor$Worker.call(RDFStreamProcessor.java:866)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Questions

What's the best way to resolve the above errors?

Thank you!

First obvious thing would be to either drop begin/commit completely (since they're unnecessary for read-only transactions) or, if somehow needed, call commit inside the finally block after the set of statements is returned. Note that query execution does not stop after execute() returns. It's lazy and stops only after the result set is closed.

Cheers,
Pavel

Thank you @pavel
A follow up question, how programatically I can check whether the result is loaded fully, e.g., there is no result.isClose() method to call, is there any way?

Maybe one way is something like below:

		CloseableIterator<Statement> aResultsIter = new CloseableIterator.AbstractCloseableIterator<Statement>() {
			@Override
			public void close() {
				aResults.close();
			}

			@Override
			protected Statement computeNext() {
				if (aResults.hasNext()) {
					return aResults.next();
				}

				return endOfData();
			}
		};

		return Streams.stream(aResultsIter);
	}

is there any other way?

Once you did result.toGraph(), you have all your results in a graph on the client, so it's all finished on the server side. In general, you either iterator over all results or close the query result set (com.stardog.stark.query.QueryResult has close()).

Cheers,
Pavel