Skip to content

Commit 8fba4ab

Browse files
authored
Fix/conn pool not remove (#289)
* fix conn pool not remove * dev test * update version
1 parent 0d47a70 commit 8fba4ab

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/main/java/com/alipay/remoting/DefaultConnectionManager.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.ArrayBlockingQueue;
2626
import java.util.concurrent.Callable;
2727
import java.util.concurrent.ConcurrentHashMap;
28+
import java.util.concurrent.ConcurrentMap;
2829
import java.util.concurrent.ExecutionException;
2930
import java.util.concurrent.FutureTask;
3031
import java.util.concurrent.RejectedExecutionException;
@@ -51,48 +52,48 @@
5152
public class DefaultConnectionManager extends AbstractLifeCycle implements ConnectionManager,
5253
Scannable, LifeCycle {
5354

54-
private static final Logger logger = BoltLoggerFactory
55-
.getLogger("CommonDefault");
55+
private static final Logger logger = BoltLoggerFactory
56+
.getLogger("CommonDefault");
5657

5758
/**
5859
* executor to create connections in async way
5960
*/
60-
private ThreadPoolExecutor asyncCreateConnectionExecutor;
61+
private ThreadPoolExecutor asyncCreateConnectionExecutor;
6162

6263
/**
6364
* connection pool initialize tasks
6465
*/
65-
protected ConcurrentHashMap<String, RunStateRecordedFutureTask<ConnectionPool>> connTasks;
66+
protected ConcurrentMap<String, RunStateRecordedFutureTask<ConnectionPool>> connTasks;
6667

6768
/**
6869
* heal connection tasks
6970
*/
70-
protected ConcurrentHashMap<String, FutureTask<Integer>> healTasks;
71+
protected ConcurrentMap<String, FutureTask<Integer>> healTasks;
7172

7273
/**
7374
* connection pool select strategy
7475
*/
75-
protected ConnectionSelectStrategy connectionSelectStrategy;
76+
protected ConnectionSelectStrategy connectionSelectStrategy;
7677

7778
/**
7879
* address parser
7980
*/
80-
protected RemotingAddressParser addressParser;
81+
protected RemotingAddressParser addressParser;
8182

8283
/**
8384
* connection factory
8485
*/
85-
protected ConnectionFactory connectionFactory;
86+
protected ConnectionFactory connectionFactory;
8687

8788
/**
8889
* connection event handler
8990
*/
90-
protected ConnectionEventHandler connectionEventHandler;
91+
protected ConnectionEventHandler connectionEventHandler;
9192

9293
/**
9394
* connection event listener
9495
*/
95-
protected ConnectionEventListener connectionEventListener;
96+
protected ConnectionEventListener connectionEventListener;
9697

9798
/**
9899
* Construct with parameters.
@@ -710,6 +711,7 @@ public ConnectionPool call() throws Exception {
710711
syncCreateNumWhenNotWarmup);
711712
} catch (Exception e) {
712713
pool.removeAllAndTryClose();
714+
connTasks.remove(url.getUniqueKey());
713715
throw e;
714716
}
715717
}
@@ -914,7 +916,7 @@ public void setConnectionEventListener(ConnectionEventListener connectionEventLi
914916
*
915917
* @return property value of connPools
916918
*/
917-
public ConcurrentHashMap<String, RunStateRecordedFutureTask<ConnectionPool>> getConnPools() {
919+
public ConcurrentMap<String, RunStateRecordedFutureTask<ConnectionPool>> getConnPools() {
918920
return this.connTasks;
919921
}
920922
}

src/main/java/com/alipay/remoting/connection/AbstractConnectionFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.alipay.remoting.config.BoltServerOption;
3232
import com.alipay.remoting.config.Configuration;
3333
import com.alipay.remoting.ExtendedNettyChannelHandler;
34+
import com.alipay.remoting.exception.RemotingException;
3435
import org.slf4j.Logger;
3536

3637
import com.alipay.remoting.Connection;
@@ -189,6 +190,8 @@ public Connection createConnection(Url url) throws Exception {
189190
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT);
190191
} else {
191192
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT_FAILED);
193+
throw new RemotingException("create connection, but channel is inactive, url is "
194+
+ url.getOriginUrl());
192195
}
193196
return conn;
194197
}
@@ -204,6 +207,9 @@ public Connection createConnection(String targetIP, int targetPort, int connectT
204207
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT);
205208
} else {
206209
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT_FAILED);
210+
throw new RemotingException(
211+
"create connection, but channel is inactive, target address is " + targetIP + ":"
212+
+ targetPort);
207213
}
208214
return conn;
209215
}
@@ -219,6 +225,9 @@ public Connection createConnection(String targetIP, int targetPort, byte version
219225
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT);
220226
} else {
221227
channel.pipeline().fireUserEventTriggered(ConnectionEventType.CONNECT_FAILED);
228+
throw new RemotingException(
229+
"create connection, but channel is inactive, target address is " + targetIP + ":"
230+
+ targetPort);
222231
}
223232
return conn;
224233
}

src/main/java/com/alipay/remoting/util/ConcurrentHashSet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.AbstractSet;
2020
import java.util.Iterator;
2121
import java.util.concurrent.ConcurrentHashMap;
22+
import java.util.concurrent.ConcurrentMap;
2223

2324
/**
2425
* Concurrent hash set.
@@ -27,7 +28,7 @@
2728
* @version $Id: ConcurrentHashSet.java, v 0.1 Mar 11, 2016 3:40:41 PM yunliang.shi Exp $
2829
*/
2930
public class ConcurrentHashSet<E> extends AbstractSet<E> {
30-
private ConcurrentHashMap<E, Boolean> map;
31+
private ConcurrentMap<E, Boolean> map;
3132

3233
/**
3334
* constructor

0 commit comments

Comments
 (0)