Bug CORE-228
1 vote

Multi-threaded access to MimeTypesHelper may fail if not previously accessed

Created by rahul on 5/17/2012 10:47 AM Last Updated by rahul on 5/24/2012 4:42 PM
%
 (hrs)
Logged: 0  (hrs)

 Description

See bottom of comments for original description

    rahul (Thursday, May 24, 2012 4:42 PM) #

Thank You Rob. The workaround that you've suggested works and have seemed to fixed the issue.

Thanks,

Rahul

    Rob Vesse (Tuesday, May 22, 2012 7:21 PM) #

Fixed URI interning multi-threading in revision 2208

    Rob Vesse (Tuesday, May 22, 2012 4:28 PM) #

Reopened, the code is now hitting a concurrency error in the URI Interning subsystem

 

The workaround is to disable URI Interning by setting Options.UriInterning to false, fix is in progress

    rahul (Tuesday, May 22, 2012 8:38 AM) #

Calling the method/property of MimeTypesHelper class at the start of my code did not fix the error. However it has removed one of the errors at - VDS.RDF.MimeTypesHelper.get_HttpAcceptHeader().

I am still getting the following error:

 

System.AggregateException: One or more errors occurred. ---> System.NullReferenc
eException: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boo
lean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at VDS.Common.TrieNode`2.AddChild(TKeyBit key)
   at VDS.Common.Trie`3.MoveToNode(TKey key)
   at VDS.RDF.UriFactory.Create(String uri)
   at VDS.RDF.NamespaceMapper..ctor(Boolean empty)
   at VDS.RDF.NamespaceMapper..ctor()
   at VDS.RDF.BaseGraph..ctor(BaseTripleCollection tripleCollection, BaseNodeCol
lection nodeCollection)
   at VDS.RDF.BaseGraph..ctor(BaseTripleCollection tripleCollection)
   at VDS.RDF.BaseGraph..ctor()
   at VDS.RDF.Graph..ctor()
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(String sparqlQuery
)
   at dotNetRdf.FusekiConcurrencyTests.Program.GetResults(String sparqlQuery) in
 C:\Users\rsharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurre
ncyTests\dotNetRdf.FusekiConcurrencyTests\Program.cs:line 40
   at dotNetRdf.FusekiConcurrencyTests.Program.<Main>b__1() in C:\Users\rsharma\
Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\dotNetRdf
.FusekiConcurrencyTests\Program.cs:line 21
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeou
t, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeou
t)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at dotNetRdf.FusekiConcurrencyTests.Program.Main(String[] args) in C:\Users\r
sharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\do
tNetRdf.FusekiConcurrencyTests\Program.cs:line 25
---> (Inner Exception #0) System.NullReferenceException: Object reference not se
t to an instance of an object.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boo
lean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at VDS.Common.TrieNode`2.AddChild(TKeyBit key)
   at VDS.Common.Trie`3.MoveToNode(TKey key)
   at VDS.RDF.UriFactory.Create(String uri)
   at VDS.RDF.NamespaceMapper..ctor(Boolean empty)
   at VDS.RDF.NamespaceMapper..ctor()
   at VDS.RDF.BaseGraph..ctor(BaseTripleCollection tripleCollection, BaseNodeCol
lection nodeCollection)
   at VDS.RDF.BaseGraph..ctor(BaseTripleCollection tripleCollection)
   at VDS.RDF.BaseGraph..ctor()
   at VDS.RDF.Graph..ctor()
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(String sparqlQuery
)
   at dotNetRdf.FusekiConcurrencyTests.Program.GetResults(String sparqlQuery) in
 C:\Users\rsharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurre
ncyTests\dotNetRdf.FusekiConcurrencyTests\Program.cs:line 40
   at dotNetRdf.FusekiConcurrencyTests.Program.<Main>b__1() in C:\Users\rsharma\
Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\dotNetRdf
.FusekiConcurrencyTests\Program.cs:line 21
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()<---
 
Press any key to exit...
 
Thank you!

 

    Rob Vesse (Monday, May 21, 2012 6:40 PM) #

Fixed in revision 2206

    Rob Vesse (Monday, May 21, 2012 6:16 PM) #

This is a synchro issue related to the fact that the code in MimeTypesHelper does a 1 time initialisation the first time it is accessed.  With your code you cause two initializations to be fired off near simultaneously and one thread tries to consume an internal list while another is trying to iniitalize it.

 

I should have a fix for this in Trunk fairly soon

 

As a workaround for the current release just call a method/propery of the MimeTypesHelper class at the start of your code to ensure the initialization happens before your parallel code kicks off e.g.

 

MimeTypesHelper.Definitions.Count();

    rahul (Thursday, May 17, 2012 11:02 AM) #

right. so the description is broken and i cant edit it or delete it.

Anyways here's the description - again!:

Testing Fuseki in terms of concurrency. Using TPL to create multiple tasks, run a few sparql queries and check if the results come back fine and the fuseki server shows no concurrency issues. Using following code:

static void Main(string[] args)

{
var tasks = new List<Task>();
 
tasks.Add(Task.Factory.StartNew(() => { GetResults(sparqlTest); Console.WriteLine(GetResults(sparqlTest)); }));
tasks.Add(Task.Factory.StartNew(() => { GetResults(sparqlTest2); Console.WriteLine(GetResults(sparqlTest2)); }));
 
try
{
Task.WaitAll(tasks.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
 
Console.ReadKey(true);
}
 
public static string GetResults(string sparqlQuery)
{
var endpoint = new SparqlRemoteEndpoint(new Uri("http://localhost:3030/query/sparql"));
 
var results = endpoint.QueryWithResultGraph(sparqlQuery);
 
if (!results.IsEmpty)
return results.Triples.FirstOrDefault().Subject.ToString();
else
return "No Results!";
}
 
private static string sparqlTest = @"CONSTRUCT
{?s ?p ?p}
where
{
SERVICE <http://localhost:3030/rahul/sparql>
{
select * where {
?s ?p ?o} limit 10
}
}";
 
private static string sparqlTest2 = @"CONSTRUCT
{?s ?p ?p}
where
{
SERVICE <http://localhost:3030/rahul2/sparql>
{
select * where {
?s ?p ?o} limit 10
}
}";
 
}
 
But I keep getting exception as below:
System.AggregateException: One or more errors occurred. ---> System.InvalidOpera
tionException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resour
ce)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at VDS.RDF.MimeTypesHelper.get_HttpAcceptHeader()
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(IRdfHandler handle
r, String sparqlQuery)
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(String sparqlQuery
)
   at dotNetRdf.FusekiConcurrencyTests.Program.GetResults(String sparqlQuery) in
 C:\Users\rsharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurre
ncyTests\dotNetRdf.FusekiConcurrencyTests\Program.cs:line 36
   at dotNetRdf.FusekiConcurrencyTests.Program.<Main>b__1() in C:\Users\rsharma\
Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\dotNetRdf
.FusekiConcurrencyTests\Program.cs:line 17
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeou
t, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeou
t)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at dotNetRdf.FusekiConcurrencyTests.Program.Main(String[] args) in C:\Users\r
sharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\do
tNetRdf.FusekiConcurrencyTests\Program.cs:line 21
---> (Inner Exception #0) System.InvalidOperationException: Collection was modif
ied; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resour
ce)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at VDS.RDF.MimeTypesHelper.get_HttpAcceptHeader()
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(IRdfHandler handle
r, String sparqlQuery)
   at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultGraph(String sparqlQuery
)
   at dotNetRdf.FusekiConcurrencyTests.Program.GetResults(String sparqlQuery) in
 C:\Users\rsharma\Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurre
ncyTests\dotNetRdf.FusekiConcurrencyTests\Program.cs:line 36
   at dotNetRdf.FusekiConcurrencyTests.Program.<Main>b__1() in C:\Users\rsharma\
Documents\Visual Studio 2010\Projects\dotNetRdf.FusekiConcurrencyTests\dotNetRdf
.FusekiConcurrencyTests\Program.cs:line 17
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()<---
 
Press any key to exit...
 
When using HttpWebRequest to request GET methods on fuseki, it runs fine. But I'm using dotNetRDF for my application and I need to make sure I can run the above tests via dotNetRDF and I can't figure out the above exception.
Can you please help me with this.
Thanks,
Rahul