summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/isode/stroke/network/PlatformDomainNameServiceQuery.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/com/isode/stroke/network/PlatformDomainNameServiceQuery.java b/src/com/isode/stroke/network/PlatformDomainNameServiceQuery.java
index 66a38cc..0fc7976 100644
--- a/src/com/isode/stroke/network/PlatformDomainNameServiceQuery.java
+++ b/src/com/isode/stroke/network/PlatformDomainNameServiceQuery.java
@@ -32,8 +32,9 @@ public class PlatformDomainNameServiceQuery extends DomainNameServiceQuery imple
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
env.put("java.naming.provider.url", "dns:");
+ DirContext ctx = null;
try {
- DirContext ctx = new InitialDirContext(env);
+ ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes(service, new String[]{"SRV"});
Attribute attribute = attrs.get("SRV");
for (int i = 0; attribute != null && i < attribute.size(); i++) {
@@ -58,7 +59,15 @@ public class PlatformDomainNameServiceQuery extends DomainNameServiceQuery imple
onResult.emit(results);
}
});
-
+ //close the context as otherwise this will lead to open sockets in
+ //CLOSE_WAIT condition
+ if(ctx != null) {
+ try {
+ ctx.close();
+ } catch (NamingException e) {
+ //at least we try to close the context
+ }
+ }
}
}