SPARQL queries run forever and cannot be terminated

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:

  1. The execution of the query is never terminated and constantly consumes CPU.
  2. Termination of the query is not possible using the Web UI because the Kill button is not accessible.
  3. 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.
  4. 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.

Hi Sebastian,
Thanks for sharing. What is LINQ?
Could you tell us what was the query timeout limit? Do you think by setting a value to 60s, the query will still run forever?

Best,
Ghislain

Dear @gatemezing,

LINQ is Language Integrated Query for Microsoft .NET. See here for more details:

The timeout was 30s I suppose. At least thats the time when the query returned in my unit tests. However, the queries continue to execute even hours after timout occured. They seem to run forever.

Thanks for taking care! :slight_smile:

Thanks, we will investigate this. Two questions though: which version of Stardog are you using (termination was substantially improved quite recently)? Are you sure there’s nothing else in the database, like OWL axioms or rules?

If we cannot reproduce this with the latest Stardog, we’ll probably ask you for the query plan and/or the thread dump (e.g. jstack output) of the running server when the query is in the terminating state.

Thanks,
Pavel

Dear @pavel,

I am using Stardog 5.3.0 64-Bit in a Ubuntu Server 18.04 VM. The database is set to RDFS reasoning, however reasoning is not enabled for the query. I have loaded the FOAF ontology and a sample dataset:

foaf.rdf (43.2 KB)
foaf-data.ttl (10.1 KB)

Great, we’ll take a look and get back to you.

Best,
Pavel

Thanks again, we were able to reproduce the problem and created ticket #5409 to track it. Should be fixed in the next release.

Best,
Pavel

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