Skip to content

Commit

Permalink
Catch exception from RecordDecoder and fail the DNS query
Browse files Browse the repository at this point in the history
When no decoder is found for a record type, RecordDecoder now throws DecoderException
instead of IllegalStateException.

The DnsClientImpl then catches this exception and fails the query, as
otherwise the handler is never called.
  • Loading branch information
mnylen committed Oct 13, 2023
1 parent 188b572 commit 419f897
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/java/io/vertx/core/dns/impl/DnsClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.netty.channel.*;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.dns.*;
import io.netty.handler.logging.LoggingHandler;
import io.netty.util.collection.LongObjectHashMap;
Expand Down Expand Up @@ -261,7 +262,14 @@ void handle(DnsResponse msg) {
List<T> records = new ArrayList<>(count);
for (int idx = 0;idx < count;idx++) {
DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx);
T record = RecordDecoder.decode(a);
T record;
try {
record = RecordDecoder.decode(a);
} catch (DecoderException e) {
fail(e);
return;
}

if (isRequestedType(a.type(), types)) {
records.add(record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static <T> T decode(DnsRecord record) {
DnsRecordType type = record.type();
Function<DnsRecord, ?> decoder = decoders.get(type);
if (decoder == null) {
throw new IllegalStateException("Unsupported resource record type [id: " + type + "].");
throw new DecoderException("DNS record decoding error occurred: Unsupported resource record type [id: " + type + "].");
}
T result = null;
try {
Expand Down

0 comments on commit 419f897

Please sign in to comment.