Skip to content

DnsClient does not sort MX and SRV records by priority #6205

Description

@shblue21

Version

5.1.2

Context

The JavaDoc for DnsClient.resolveMX() says the returned list is sorted by priority:

@return a future notified with a List that contains all resolved {@link MxRecord}s, sorted by
        their {@link MxRecord#priority()}.

The DNS guide also says MX and SRV records with smaller priority values should come first.

However, Vert.x appears to keep the order from the DNS response. For example, if the server returns priorities 20 and then 10, Vert.x returns them in that order instead of 10 and then 20.

Applications relying on this ordering may then select the wrong mail exchanger or service endpoint.

Steps to reproduce

mockDnsServer.store(question -> Arrays.asList(
  MockDnsServer.mx("vertx.io", 100, "mx-high.vertx.io", 20),
  MockDnsServer.mx("vertx.io", 100, "mx-low.vertx.io", 10)
));

DnsClient dns = prepareDns();

List<MxRecord> records = dns.resolveMX("vertx.io").await();
records.forEach(record ->
  System.out.println(record.priority() + ": " + record.name()));

Expected output

10: mx-low.vertx.io
20: mx-high.vertx.io

Actual output

20: mx-high.vertx.io
10: mx-low.vertx.io

Do you have a reproducer?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions