# IndexConnection must be open

**URL:** <https://community.stardog.com/t/indexconnection-must-be-open/2008>\
**Category:** Support\
**Created:** [October 15, 2019, 12:07pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008 "2019-10-15T12:07:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shishir\_Singhal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/shishir_singhal/32/494_2.png) [@Shishir\_Singhal](https://community.stardog.com/u/Shishir_Singhal)\
**Post date:** [October 15, 2019, 12:07pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008/1 "2019-10-15T12:07:20Z")

</div>

Sometimes whenever I am trying to find out the count of predicates in my data using group by and count operator. It is giving me "IndexConnection must be open." error.  
What is that error is about?  
Please help me to remove this error.

server status:  
Connection Timeout : 10m  
Export Storage Directory : .exports  
Memory Heap : 3.3G (Max: 11G)  
Memory Mode : DEFAULT  
Memory Query Blocks : 0B (Max: 4.6G)  
Memory RSS : 18G  
Platform Arch : amd64  
Platform OS : Linux 3.10.0-693.5.2.el7.x86\_64, Java 1.8.0\_151  
Query All Graphs : false  
Query Timeout : 30m  
Security Disabled : false

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [October 15, 2019, 12:30pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008/2 "2019-10-15T12:30:07Z")

</div>

Hi! Can you please share the query you are running, explain out (query plan) and the stack trace for the server log? Which version of Stardog and roughly how large your database is?

---

<div class="post-metadata">

**Author:** ![Shishir\_Singhal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/shishir_singhal/32/494_2.png) [@Shishir\_Singhal](https://community.stardog.com/u/Shishir_Singhal)\
**Post date:** [October 15, 2019, 12:59pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008/3 "2019-10-15T12:59:27Z")

</div>

Hi,  
prefix : [http://rdf.freebase.com/ns/](http://rdf.freebase.com/ns/)  
prefix key: [http://rdf.freebase.com/key/en](http://rdf.freebase.com/key/en)

Query:  
select ?p (count(\*) as ?count){  
?s ?p ?o .  
} group by(?p) order by desc(?count)  
limit 10  
I am using freebase(3.2 billion triples)  
stack trace:  
ERROR 2019-10-15 17:22:44,012 [stardog-user-14] com.complexible.stardog.protocols.http.server.StardogHttpServiceLoader:accept(231): An unexpected exception was handled by the server  
com.stardog.stark.query.QueryExecutionFailure: IndexConnection must be open.  
at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:82) ~[stardog-utils-rdf-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.TransactionManagedQueryResult.hasNext(TransactionManagedQueryResult.java:61) ~[stardog-7.0.2.jar:?]  
at com.stardog.stark.query.ClosingSpliterator.forEachRemaining(ClosingSpliterator.java:37) ~[stardog-stark-query-api-7.0.2.jar:?]  
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) ~[?:1.8.0\_151]  
at com.stardog.stark.query.io.QueryResultWriters.write(QueryResultWriters.java:142) ~[stardog-stark-query-io-7.0.2.jar:?]  
at com.stardog.stark.query.io.QueryResultWriters.write(QueryResultWriters.java:127) ~[stardog-stark-query-io-7.0.2.jar:?]  
at com.complexible.stardog.protocols.http.server.ProtocolUtils.writeTupleResponse(ProtocolUtils.java:570) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeReadQuery(ProtocolUtils.java:480) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at com.complexible.stardog.protocols.http.server.ProtocolUtils.executeReadQuery(ProtocolUtils.java:464) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at com.complexible.stardog.protocols.http.server.SPARQLProtocol.executeQuery(SPARQLProtocol.java:127) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at com.complexible.stardog.protocols.http.server.SPARQLProtocol.get(SPARQLProtocol.java:83) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$5(ExtractRoutes.java:192) ~[stardog-protocols-http-server-7.0.2.jar:?]  
at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) [shiro-core-1.3.0.jar:1.3.0]  
at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) [shiro-core-1.3.0.jar:1.3.0]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0\_151]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0\_151]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_151]  
Caused by: java.lang.IllegalStateException: IndexConnection must be open.  
at com.google.common.base.Preconditions.checkState(Preconditions.java:507) ~[guava-26.0-jre.jar:?]  
at com.complexible.stardog.index.BaseIndexConnection.assertOpen(BaseIndexConnection.java:132) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.index.BaseIndexConnection.getIndex(BaseIndexConnection.java:49) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.index.mvcc.MvccIndexConnection.begin(MvccIndexConnection.java:125) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.index.impl.DelegatingIndexConnection.begin(DelegatingIndexConnection.java:85) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.index.impl.DelegatingIndexConnection.begin(DelegatingIndexConnection.java:85) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.index.IndexUtils.initTx(IndexUtils.java:91) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.ExecutionContext.getReader(ExecutionContext.java:249) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.ExecutionContext.getMappings(ExecutionContext.java:266) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.AbstractOperator.getMappings(AbstractOperator.java:76) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.project(SingleProjectionOp.java:112) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:88) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SingleProjectionOp.computeNext(SingleProjectionOp.java:29) ~[stardog-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:147) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:134) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.\_hasNext(SliceOp.java:87) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.computeNext(SliceOp.java:95) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.impl.SliceOp.computeNext(SliceOp.java:26) ~[stardog-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:147) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:134) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:114) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.AutoCloseOperator.computeNext(AutoCloseOperator.java:26) ~[stardog-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.tryToComputeNext(AbstractSkippingIterator.java:147) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.common.collect.AbstractSkippingIterator.hasNext(AbstractSkippingIterator.java:134) ~[stardog-utils-common-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:119) ~[stardog-7.0.2.jar:?]  
at com.complexible.stardog.plan.eval.operator.util.OpBasedBindingSetIteration.computeNext(OpBasedBindingSetIteration.java:40) ~[stardog-7.0.2.jar:?]  
at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141) ~[guava-26.0-jre.jar:?]  
at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136) ~[guava-26.0-jre.jar:?]  
at com.complexible.common.rdf.query.IteratorAsTupleQueryResult.hasNext(IteratorAsTupleQueryResult.java:78) ~[stardog-utils-rdf-7.0.2.jar:?]  
... 16 more

---

<div class="post-metadata">

**Author:** ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)\
**Post date:** [October 15, 2019, 1:36pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008/4 "2019-10-15T13:36:15Z")

</div>

We will need to improve the error message but the likely reason is that the database connection was closed on timeout while the query was running. This is a very expensive query since it needs to count triples for every predicate before returning the most frequently occurring ones. Try to set `database.connection.timeout` to something very high, like `1h`, in `stardog.properties` before restarting the server.

Cheers,  
Pavel

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [October 29, 2019, 1:36pm UTC](https://community.stardog.com/t/indexconnection-must-be-open/2008/5 "2019-10-29T13:36:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
