0

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 ?

  • Should be migrated to Code Review. – Dávid Horváth Apr 07 '17 at 14:37
  • @DávidHorváth I'm not convinced this code works as intended. If it doesn't work as intended, it's not welcome at Code Review. – Mast Apr 07 '17 at 14:39
  • can you show what does executeQueryAsync functions do? Also it looks like *An existing connection was forcibly closed by the remote host* indicates some error at RavenDB server-side. Do you see any errors in fiddler? Or RavenDB debug log? – Michael Apr 10 '17 at 10:16

0 Answers0