Skip to content

Commit 20df136

Browse files
author
chengyitian
committed
AJ-475: close conn for AbstractClient checkServerVersion();
1 parent ed04bbc commit 20df136

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/com/xxdb/streaming/client/AbstractClient.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -600,33 +600,39 @@ protected void unsubscribeInternal(String host, int port, String tableName) thro
600600

601601
void checkServerVersion(String host, int port) throws IOException {
602602
DBConnection conn = new DBConnection();
603-
conn.connect(host, port);
604-
String version = conn.run("version()").getString();
605-
606-
String[] _ = version.split(" ")[0].split("\\.");
607-
int v0 = Integer.parseInt(_[0]);
608-
int v1 = Integer.parseInt(_[1]);
609-
int v2 = Integer.parseInt(_[2]);
610-
611-
if((v0 == 2 && v1 == 0 && v2 >= 9) || (v0 == 2 && v1 == 10) || (v0 == 3 && v1 == 0 && v2 >= 0)){
612-
//server only support reverse connection
613-
listeningPort = 0;
614-
}else{
615-
//server Not support reverse connection
616-
if(listeningPort == 0){
617-
throw new IOException("The server does not support subscription through reverse connection (connection initiated by the subscriber). Specify a valid port parameter.");
603+
try {
604+
conn.connect(host, port);
605+
String version = conn.run("version()").getString();
606+
607+
String[] _ = version.split(" ")[0].split("\\.");
608+
int v0 = Integer.parseInt(_[0]);
609+
int v1 = Integer.parseInt(_[1]);
610+
int v2 = Integer.parseInt(_[2]);
611+
612+
if ((v0 == 2 && v1 == 0 && v2 >= 9) || (v0 == 2 && v1 == 10) || (v0 == 3 && v1 == 0 && v2 >= 0)) {
613+
//server only support reverse connection
614+
this.listeningPort = 0;
615+
} else {
616+
//server Not support reverse connection
617+
if (this.listeningPort == 0)
618+
throw new IOException("The server does not support subscription through reverse connection (connection initiated by the subscriber). Specify a valid port parameter.");
618619
}
619-
}
620-
if(daemon == null) {
621-
synchronized (connList) {
622-
if(daemon == null) {
623-
daemon = new Daemon(this.listeningPort, this, connList);
624-
pThread = new Thread(daemon);
625-
daemon.setRunningThread(pThread);
626-
pThread.start();
620+
if(daemon == null) {
621+
synchronized (connList) {
622+
if(daemon == null) {
623+
daemon = new Daemon(this.listeningPort, this, connList);
624+
pThread = new Thread(daemon);
625+
daemon.setRunningThread(pThread);
626+
pThread.start();
627+
}
627628
}
628629
}
630+
} finally {
631+
conn.close();
629632
}
630633
}
631-
public ConcurrentHashMap<String, AbstractClient.Site[]> getTopicToSites(){return trueTopicToSites;}
634+
635+
public ConcurrentHashMap<String, AbstractClient.Site[]> getTopicToSites() {
636+
return trueTopicToSites;
637+
}
632638
}

0 commit comments

Comments
 (0)