I'm working on a project that computes a continuous flow of data. I've been strugling lately with some memory and networking exceptions to the point where I ask myself if the way i'm getting the data from my database is good.
I am using:
- .NET 4.6.1
- Akka.NET 1.0.8
- RavenDB.Client 3.5.1
Here's an example of how I load data into my actors:
public class MyActor : ReceiveActor
{
public MyActor (ImmutableRegistration registration)
{
Receives();
Self.Tell(new InitDBCache());
}
private void Receives()
{
Receive<InitDBCache>(t =>
{
var builder = new DataBaseCacheBuilder();
builder.BuildFor(registration).ContinueWith(result =>
{
return new DBCacheReceived(result.Result);
},
TaskContinuationOptions.AttachedToParent &
TaskContinuationOptions.ExecuteSynchronously).PipeTo(Self);
});
Receive<DBCacheReceived>(msg =>
{
// Init actor with retrieved data
});
}
private sealed class InitDBCache
{
public InitDBCache() { }
}
private sealed class DBCacheReceived
{
public DBCacheReceived(DataBaseCache cache)
{
this.Cache = cache;
}
public DataBaseCache Cache { get; }
}
}
The DataBaseCacheBuilder goes like this :
public sealed class DataBaseCacheBuilder
{
public DataBaseCacheBuilder()
{
}
public async Task<DataBaseCache> BuildFor(ImmutableRegistration registration)
{
// I have a repository pattern on top of the ravendb client
using (var session = OutsideRefs.DataStore.OpenRavenDbSession())
{
var queryResult1 = await session.repository1.executeQueryAsync(registration.Id);
var queryResult2 = await session.repository2.executeQueryAsync(registration.Id);
return new DataBaseCache(queryResult1, queryResult2);
}
}
}
Concretely, my program throws a fair number of "System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Those exceptions are throwed by the ravendb client.
Does anyone see a problem or a correlation with my code and the exception ?
Does using async/await to regroup async calls a bad thing to do even though I'm piping the result ?