mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-15 10:55:27 +01:00
fix dns memory leak
This commit is contained in:
parent
9521ee1ca0
commit
c3178d8531
@ -30,6 +30,7 @@ import io.netty.handler.codec.dns.DefaultDnsQuestion
|
||||
import io.netty.handler.codec.dns.DefaultDnsRawRecord
|
||||
import io.netty.handler.codec.dns.DefaultDnsRecordDecoder
|
||||
import io.netty.handler.codec.dns.DnsRecordType
|
||||
import io.netty.util.ReferenceCountUtil
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.math.BigInteger
|
||||
import java.net.InetAddress
|
||||
@ -57,10 +58,11 @@ suspend fun resolveSrv(hostAndPort: HostAndPort): HostAndPort {
|
||||
if (hostAndPort.port == 25565) {
|
||||
try {
|
||||
// stolen from PacketLib (MIT) https://github.com/Camotoy/PacketLib/blob/312cff5f975be54cf2d92208ae2947dbda8b9f59/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java
|
||||
dnsResolver
|
||||
val records = dnsResolver
|
||||
.resolveAll(DefaultDnsQuestion("_minecraft._tcp.${hostAndPort.host}", DnsRecordType.SRV))
|
||||
.suspendAwait()
|
||||
.forEach { record ->
|
||||
try {
|
||||
records.forEach { record ->
|
||||
if (record is DefaultDnsRawRecord && record.type() == DnsRecordType.SRV) {
|
||||
val content = record.content()
|
||||
|
||||
@ -71,6 +73,9 @@ suspend fun resolveSrv(hostAndPort: HostAndPort): HostAndPort {
|
||||
return HostAndPort.fromParts(address, port)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
records.forEach { ReferenceCountUtil.release(it) }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
viaaasLogger.debug("Couldn't resolve SRV", e)
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import io.ktor.websocket.*
|
||||
import io.netty.handler.codec.dns.DefaultDnsQuestion
|
||||
import io.netty.handler.codec.dns.DnsPtrRecord
|
||||
import io.netty.handler.codec.dns.DnsRecordType
|
||||
import io.netty.util.ReferenceCountUtil
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.future.asCompletableFuture
|
||||
import java.net.InetSocketAddress
|
||||
@ -100,7 +101,13 @@ class WebDashboardServer {
|
||||
DefaultDnsQuestion(reverseLookup(it.address), DnsRecordType.PTR)
|
||||
)
|
||||
info = ipLookup.await()
|
||||
ptr = dnsQuery.suspendAwait().firstNotNullOfOrNull { it as? DnsPtrRecord }?.hostname()
|
||||
ptr = dnsQuery.suspendAwait().let {
|
||||
try {
|
||||
it.firstNotNullOfOrNull { it as? DnsPtrRecord }?.hostname()
|
||||
} finally {
|
||||
it.forEach { ReferenceCountUtil.release(it) }
|
||||
}
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user