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

TimeoutException causes leakage of connections in several servers #139

Open
fooling opened this issue Jun 1, 2023 · 0 comments
Open

TimeoutException causes leakage of connections in several servers #139

fooling opened this issue Jun 1, 2023 · 0 comments

Comments

@fooling
Copy link

fooling commented Jun 1, 2023

After connection timeout from the initialization, failed address will be added to a waiting queue:

        this.connector.addToWatingQueue(
            new ReconnectRequest(inetSocketAddressWrapper, 0, getHealSessionInterval()));
        log.error("Connect to " + SystemUtils.getRawAddress(inetSocketAddress) + ":"
            + inetSocketAddress.getPort() + " fail", throwable);

Stacktrace of the exception:

java.util.concurrent.TimeoutException: null

        at com.google.code.yanf4j.core.impl.FutureImpl.get(FutureImpl.java:143) ~[xmemcached-2.4.7.jar:?]

        at net.rubyeye.xmemcached.XMemcachedClient.connect(XMemcachedClient.java:565) [xmemcached-2.4.7.jar:?]

        at net.rubyeye.xmemcached.XMemcachedClient.<init>(XMemcachedClient.java:840) [xmemcached-2.4.7.jar:?]

        at net.rubyeye.xmemcached.XMemcachedClientBuilder.build(XMemcachedClientBuilder.java:362) [xmemcached-2.4.7.jar:?]

such code in MemcachedConnector.java causes the infinite loop:

          try {
             log.info("Trying to connect to " + address.getAddress().getHostAddress() + ":"
                 + address.getPort() + " for " + request.getTries() + " times");
             if (!future.get(MemcachedClient.DEFAULT_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)) {
               connected = false;
             } else {
               connected = true;
             }
           } catch (TimeoutException e) {
             future.cancel(true);
           } catch (ExecutionException e) {
             future.cancel(true);
           } finally {
             if (!connected) {
               this.rescheduleConnectRequest(request);
             } else {
               continue;
             }
           }
         }

When future.get(MemcachedClient.DEFAULT_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) timed out 60 seconds , TimeoutException will be thrown ,and future.cancel(true) is called.

But , the underlying connections is actually established fron the netstat , and the cancellation didn't really cancel the connection. So the connection size keeps growing, there were 2000+ ESTABLISHED connections to a single destination, even if connection pool config is default(1).

Network delay is actually within 10ms.

Maybe somewhere blocked in Reactor?

@fooling fooling changed the title TimeoutException 导致到个别服务端连接数泄漏 TimeoutException causes leakage of connections in several servers Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant