Fix resource leak in DnsNameResolver
This commit is contained in:
parent
0b0544d464
commit
c5bbd3c318
@ -751,7 +751,6 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
private final class DnsResponseHandler extends ChannelInboundHandlerAdapter {
|
private final class DnsResponseHandler extends ChannelInboundHandlerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
boolean success = false;
|
|
||||||
try {
|
try {
|
||||||
final DnsResponse res = (DnsResponse) msg;
|
final DnsResponse res = (DnsResponse) msg;
|
||||||
final int queryId = res.header().id();
|
final int queryId = res.header().id();
|
||||||
@ -790,8 +789,7 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
if (res.header().responseCode() == DnsResponseCode.NOERROR) {
|
if (res.header().responseCode() == DnsResponseCode.NOERROR) {
|
||||||
cache(q, res);
|
cache(q, res);
|
||||||
promises.set(queryId, null);
|
promises.set(queryId, null);
|
||||||
qCtx.promise().trySuccess(res);
|
qCtx.promise().trySuccess(res.retain());
|
||||||
success = true;
|
|
||||||
} else {
|
} else {
|
||||||
qCtx.retry(res.sender(),
|
qCtx.retry(res.sender(),
|
||||||
"response code: " + res.header().responseCode() +
|
"response code: " + res.header().responseCode() +
|
||||||
@ -799,9 +797,7 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
res.authorityResources().size() + " authority resource(s)");
|
res.authorityResources().size() + " authority resource(s)");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
ReferenceCountUtil.safeRelease(msg);
|
||||||
ReferenceCountUtil.safeRelease(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,8 +819,6 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
// Ensure that the found TTL is between minTtl and maxTtl.
|
// Ensure that the found TTL is between minTtl and maxTtl.
|
||||||
ttl = Math.max(minTtl(), Math.min(maxTtl, ttl));
|
ttl = Math.max(minTtl(), Math.min(maxTtl, ttl));
|
||||||
|
|
||||||
res.retain();
|
|
||||||
|
|
||||||
DnsNameResolver.this.cache(question, new DnsCacheEntry(res), ttl);
|
DnsNameResolver.this.cache(question, new DnsCacheEntry(res), ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,7 +834,7 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
volatile ScheduledFuture<?> expirationFuture;
|
volatile ScheduledFuture<?> expirationFuture;
|
||||||
|
|
||||||
DnsCacheEntry(DnsResponse response) {
|
DnsCacheEntry(DnsResponse response) {
|
||||||
this.response = response;
|
this.response = response.retain();
|
||||||
cause = null;
|
cause = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user