Disclaimer: This is part of a LINQ to SPARQL generator that we are developing. The following query was generated due to an error in variable handling in our generator. It is semantically pointless but still syntactically correct. The error is fixed now but I still want to share the knowledge so that the issue can be addressed.
Consider the following query:
SELECT ?s_ ?p_ ?o_
FROM <http://example.org/test>
WHERE
{
?s_ ?p_ ?o_ .
?s_ <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
{
{
SELECT DISTINCT ?s_ ( SAMPLE ( ?o0 ) AS ?o0_sample )
WHERE
{
?s_ <http://xmlns.com/foaf/0.1/knows> ?o0 .
?s_ <http://xmlns.com/foaf/0.1/firstName> ?o1 .
FILTER ( ?o1 = 'Alice' )
}
GROUP BY ?s_
}
}
{
{
SELECT DISTINCT ?s_ ( SAMPLE ( ?o2 ) AS ?o2_sample )
WHERE
{
?s_ <http://xmlns.com/foaf/0.1/knows> ?o0 .
?s_ <http://xmlns.com/foaf/0.1/firstName> ?o1 .
FILTER ( ?o1 = 'Bob' )
}
GROUP BY ?s_
}
}
{
{
SELECT DISTINCT ?s_ ( SAMPLE ( ?o3 ) AS ?o3_sample )
WHERE
{
?s_ <http://xmlns.com/foaf/0.1/knows> ?o0 .
?s_ <http://xmlns.com/foaf/0.1/firstName> ?o1 .
FILTER ( ?o1 = 'Eve' )
}
GROUP BY ?s_
}
}
}
And consider the following dataset:
ex:Alice a foaf:Person ; foaf:firstName 'Alice' .
ex:Bob a foaf:Person ; foaf:firstName 'Bob' ; foaf:knows ex:Alice.
When executing the query against the model without reasoning, the following problems occur:
- The execution of the query is never terminated and constantly consumes CPU.
- Termination of the query is not possible using the Web UI because the Kill button is not accessible.
- Termination of the query is not possible using the command line
stardog-admin query kill X
. The command executes with a result ‘OK’, but the query remains in a ‘Terminating’ state continues to consume CPU. - Termination of the query is not possible by
stardog-admin server stop
; the server continues to run and execute the queries.
This can eventually be used / accidentally result in a DOS attack because one can issue an arbitrary number of these malformed queries and effectively use up all resources in the system.
The only solution I found was to kill the server. However, this may result in data loss.