1

I have a windows desktop application on .NET Framework that a user can interact with. There is a "connect" button that sets up Apache Geode client connection to Geode Server.

When Geode Server is down (Locator - there is only 1) the desktop application hangs indefinitely and needs to be forcefully closed.

This is how we connenect to the server and hangs on last line indefinitely:

                PoolFactory poolFactory = _cache.GetPoolManager()
                .CreateFactory()
                .SetSubscriptionEnabled(true)
                .AddLocator(_host, _port);

            return poolFactory.Create(_serviceName);

I would like to add a time-out period for this method to return or throw exceptions or anything.

Alternatively, I've wrapped it on a different kind of timer outside of this to just return, but when trying to run the above code again (to try to connect the application again) the pool is still trying to connect. I have tried to destroy it like this:

              //destroy the pool
            var poolManager = _cache.GetPoolManager();
            if (poolManager != null)
            {
                var pool = poolManager.Find(_serviceName);
                if (pool != null && pool.Destroyed == false)
                    pool.Destroy();
            }

But then the pool.Destroy(); hangs indefinateley

How can I have a mechanism to attempt to connect to the Geode server, return if not connected within 10 seconds, then leave and are able to try to connect again using the same cache?

Note above was trying to re-use the same cache, probably setting cache to null and trying all over again would work, but I am looking for a more correct way to do it.

Edgaras
  • 449
  • 3
  • 14

1 Answers1

0

Depending on what version of .NET native client you are using. There is a property in 10.x connect-timeout that should work. Additionally, you can wrap your connection code under try{...}catch{} block and handle an exception for Apache.Geode.Client.TimeoutException and/or ": No locators available".

Example:

    var _cache = new CacheFactory()
                        .Set("log-level", "config")
                        .Set("log-file", "C:\temp\test.log")
                        .Set("connect-timeout", "26000ms")
                        .Create();

    _cache.GetPoolManager()
        .CreateFactory()
        .SetSubscriptionEnabled(true)
        .AddLocator(hostname-or-ip", port-number)
        .Create("TestPool");
  • Thanks for the reply. I am on native client 10.x. The cache doesn't have a method to add connect-timeout. I am trying to add it where my first code snipper is in the question. Maybe you could also point to documentation where this can be set, as I couldn't find any info for connect-timeout. – Edgaras Mar 24 '21 at 15:32
  • 1
    Alright, I have edited my answer with a sample code. Hope that helps. Good luck. Here's the doc link: https://gemfire-native-dotnet.docs.pivotal.io/102/geode-native-client-dotnet/configuring/sysprops.html – Deepak Khopade Mar 24 '21 at 18:17
  • "500ms" took 3,094ms to timeout and it didn't throw any exceptions, so I checked if Pool.Servers == null instead. I believe we are using version 1.10.0. Thanks again Deepak – Edgaras Mar 25 '21 at 10:40