Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure client for azure #415

Open
mocox opened this issue Jun 19, 2021 · 3 comments
Open

How to configure client for azure #415

mocox opened this issue Jun 19, 2021 · 3 comments
Assignees
Labels

Comments

@mocox
Copy link

mocox commented Jun 19, 2021

When deployed to Azure app service the client disconnects after a period of idleness.
I saw something that need to keepsockeralive but it is read only in your code and i cant seem to find a way to get it to work on azure.

Anyone know how to configure this?

I have tried in code to connect again of it has disconnected but it just throws and error again.

Neo4j.Driver.ServiceUnavailableException: Failed after retried for 2 times in 30000 ms. Make sure that your database is online and retry again.
---> System.AggregateException: One or more errors occurred. (Failed to connect to any routing server. Please make sure that the cluster is up and can be accessed by the driver and retry.) (Failed to connect to any routing server. Please make sure that the cluster is up and can be accessed by the driver and retry.)
---> Neo4j.Driver.ServiceUnavailableException: Failed to connect to any routing server. Please make sure that the cluster is up and can be accessed by the driver and retry.
at Neo4j.Driver.Internal.Routing.RoutingTableManager.UpdateRoutingTableAsync(AccessMode mode, String database, Bookmark bookmark)
at Neo4j.Driver.Internal.Routing.RoutingTableManager.EnsureRoutingTableForModeAsync(AccessMode mode, String database, Bookmark bookmark)
at Neo4j.Driver.Internal.Routing.LoadBalancer.AcquireConnectionAsync(AccessMode mode, String database, Bookmark bookmark)
at Neo4j.Driver.Internal.Routing.LoadBalancer.AcquireAsync(AccessMode mode, String database, Bookmark bookmark)
at Neo4j.Driver.Internal.AsyncSession.BeginTransactionWithoutLoggingAsync(AccessMode mode, Action1 action, Boolean disposeUnconsumedSessionResult) at Neo4j.Driver.Internal.AsyncSession.<>c__DisplayClass37_01.<b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Neo4j.Driver.Internal.AsyncRetryLogic.RetryAsync[T](Func1 runTxAsyncFunc) --- End of inner exception stack trace --- ---> (Inner Exception #1) Neo4j.Driver.ServiceUnavailableException: Failed to connect to any routing server. Please make sure that the cluster is up and can be accessed by the driver and retry. at Neo4j.Driver.Internal.Routing.RoutingTableManager.UpdateRoutingTableAsync(AccessMode mode, String database, Bookmark bookmark) at Neo4j.Driver.Internal.Routing.RoutingTableManager.EnsureRoutingTableForModeAsync(AccessMode mode, String database, Bookmark bookmark) at Neo4j.Driver.Internal.Routing.LoadBalancer.AcquireConnectionAsync(AccessMode mode, String database, Bookmark bookmark) at Neo4j.Driver.Internal.Routing.LoadBalancer.AcquireAsync(AccessMode mode, String database, Bookmark bookmark) at Neo4j.Driver.Internal.AsyncSession.BeginTransactionWithoutLoggingAsync(AccessMode mode, Action1 action, Boolean disposeUnconsumedSessionResult)
at Neo4j.Driver.Internal.AsyncSession.<>c__DisplayClass37_01.<<RunTransactionAsync>b__1>d.MoveNext() --- End of stack trace from previous location --- at Neo4j.Driver.Internal.AsyncRetryLogic.RetryAsync[T](Func1 runTxAsyncFunc)<---

--- End of inner exception stack trace ---
at Neo4j.Driver.Internal.AsyncRetryLogic.RetryAsync[T](Func1 runTxAsyncFunc) at Neo4j.Driver.Internal.AsyncSession.<>c__DisplayClass37_01.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Neo4j.Driver.Internal.Logging.DriverLoggerUtil.TryExecuteAsync[T](ILogger logger, Func`1 func, String message)
at Neo4jClient.BoltGraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync[TResult](CypherQuery query)
at Memgroups.Providers.Neo.AdminRepository.GetGroupCount() in D:\a\1\s\Memgroups.Providers\Neo\AdminRepository.cs:line 54
at Memgroups.Api.Controllers.NeoAdminController.GetEntityCounts() in D:\a\1\s\Memgroups.Api\Controllers\NeoAdminController.cs:line 55

@andrey-kastryukhin
Copy link
Contributor

@mocox
Did you find any solution/workaround for that?

@lukacs-peter
Copy link

I'm facing the same issue, any update on this?
My current workaround is using the client as a scoped service instead of singleton, but of course this won't be a solution in production environment

@Clooney24
Copy link
Contributor

@lukacs-peter we are using it as Singleton in an Azure WebApp and solved the timeout issue like this:

           var tryCount = 0;

            if (_rootUri == null)
                SetCredentials();

            TryToConnect:

            try
            {
                tryCount++;

                IGraphClient graphClient;

                if (_useBolt)
                {
                    var driver = GraphDatabase.Driver(_rootUri, 
                        AuthTokens.Basic(_username, _password),
                        config => config
                            .WithConnectionAcquisitionTimeout(TimeSpan.FromSeconds(15))
                            .WithConnectionIdleTimeout(TimeSpan.FromMinutes(3))
                            .WithSocketKeepAliveEnabled(true)); // prevent connection timeouts

                    graphClient = new BoltGraphClient(driver)
                    {
                        JsonContractResolver = new Neo4jContractResolver(),
                        DefaultDatabase = Database
                    };
                }
                else
                {
                    graphClient = new GraphClient(_rootUri, _username, _password)
                    {
                        JsonContractResolver = new Neo4jContractResolver(),
                        DefaultDatabase = Database
                    };
                }

                ServicePointManager.ServerCertificateValidationCallback = (obj, certificate, chain, errors) => (true);

                await graphClient.ConnectAsync();

                if (!graphClient.IsConnected)
                    throw new GraphClientException($"graphClient was not able to establish connection to ({_rootUri})!");

                return graphClient;
            }
            catch (Exception ex)
            {
                if (tryCount <= 30)
                {
                    await AiLogger.LogAsync(ex, null, true, false, null, "Trying again in 10 seconds!");
                    Thread.Sleep(10000);
                    goto TryToConnect;
                }

                await AiLogger.LogAsync(ex, null, true, true);

                throw;
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants