Java client hangs when executing a SPARQL select query

Hi,

Every once in a while the Java Stardog client is hanging on select queries. After 5 minutes it still hasn't recovered.

After debugging, I think the problem is a timeout in httpclient that is set to 0.

Server status:

bash-4.3# ./stardog-admin server status
Backup Storage Directory : .backup
CPU Load                 : 0.0000 %
Connection Timeout       : 1h
Export Storage Directory : .exports
Memory Heap              : 140M (Allocated: 338M Max: 910M)
Memory Non-Heap          : 108M (Allocated: 111M Max: 1.0G)
Platform Arch            : amd64
Platform OS              : Linux 4.9.12-moby, Java 1.8.0_111-internal
Query All Graphs         : false
Query Timeout            : 5m
Stardog Home             : /home/stardog/data
Stardog Version          : 4.2.3
Strict Parsing           : true
Uptime                   : 25 minutes 50 seconds
Watchdog Enabled         : true
Watchdog Port            : 5833
Watchdog Remote Access   : true
Databases                : 
+------------+------------+-------------+-----------------+----------------------+-----------+
|    Name    | Conn. Open | Trans. Open | Running Queries | Query Avg. Time (ms) | Query/sec |
+------------+------------+-------------+-----------------+----------------------+-----------+
| testSesame |          0 |           0 |               0 |                  0.0 |       0.0 |
+------------+------------+-------------+-----------------+----------------------+-----------+


Seems like I may have been forgetting to close my streams. I’m using Iterations.stream and thought that that would close my stream when it was completed, but it doesn’t.

Rewriting my code to close my streams has solved this issue.

SelectQuery query = connection
    .select("select ?dato where {?a <" + Arkiv.publisertDato + "> ?dato} limit 1")
    .parameter("a", repository.getIdAsResource());

try (Stream<BindingSet> stream = Iterations.stream(query.execute())) {
    return stream
                 .map(next -> DateTime.parse(next.getBinding("dato").getValue().stringValue()))
                 .findAny();
}
1 Like