diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java index 873fb02b..02505013 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java @@ -146,11 +146,14 @@ public class TcpClientSession extends TcpSession { System.out.println("[PacketLib] Attempting SRV lookup for \"" + name + "\"."); } + DnsNameResolver resolver = null; AddressedEnvelope envelope = null; - try(DnsNameResolver resolver = new DnsNameResolverBuilder(this.group.next()) - .channelType(NioDatagramChannel.class) - .build()) { + try { + resolver = new DnsNameResolverBuilder(this.group.next()) + .channelType(NioDatagramChannel.class) + .build(); envelope = resolver.query(new DefaultDnsQuestion(name, DnsRecordType.SRV)).get(); + DnsResponse response = envelope.content(); if(response.count(DnsSection.ANSWER) > 0) { DefaultDnsRawRecord record = response.recordAt(DnsSection.ANSWER, 0); @@ -185,6 +188,10 @@ public class TcpClientSession extends TcpSession { if(envelope != null) { envelope.release(); } + + if(resolver != null) { + resolver.close(); + } } }