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

use promise mode,MaxConnectionSemaphore do not relase lock until channel close. #1924

Open
zxspopo opened this issue Jan 19, 2024 · 2 comments

Comments

@zxspopo
Copy link

zxspopo commented Jan 19, 2024

hi,when i use this code , i found MaxConnectionSemaphore don`t release,cause TooManyConnection Excetion.

DefaultAsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().setConnectTimeout(60000)
              .setReadTimeout(60000).setRequestTimeout(60000).setMaxConnections(200).setMaxRequestRetry(3).setAcquireFreeChannelTimeout(60000).build();
      AsyncHttpClient asyncHttpClient = Dsl.asyncHttpClient(config);
while (true) {

           String requestUrl ="http://xxx:8080/hello?name=san";
          CompletableFuture<Response> future = asyncHttpClient.prepareGet(requestUrl).execute(new HttpCompletionHandler()).toCompletableFuture();
          future.whenComplete((response, throwable) -> {
              if (throwable == null) {
               
                  // System.out.println(response.getResponseBody());
              } else {
                  if (throwable instanceof TimeoutException) {
                      System.err.println(throwable.getMessage());
                  } else {
                      // 请求失败
                      throwable.printStackTrace();
                  }
              }
          });
          // });
      }

change code like this maybe resolve this problem, is it correct?
NettyConnectListener.java

  public void onSuccess(Channel channel, InetSocketAddress remoteAddress) {

    if (connectionSemaphore != null) {
      // transfer lock from future to channel
      **//Object partitionKeyLock = future.takePartitionKeyLock();
     //change this code 
      Object partitionKeyLock = future.getPartitionKey();**

      if (partitionKeyLock != null) {
        channel.closeFuture().addListener(future -> connectionSemaphore.releaseChannelLock(partitionKeyLock));
      }
    }
@hyperxpro
Copy link
Member

Version?

@zxspopo
Copy link
Author

zxspopo commented Jan 19, 2024

@hyperxpro 2.12.3 tks

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

2 participants