-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow valid SRV hostnames with less than 3 parts #1525
base: main
Are you sure you want to change the base?
Conversation
63c5ffe
to
86b3b81
Compare
c3d2782
to
36811a2
Compare
36811a2
to
49ee4c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just a few comments/questions.
driver-core/src/main/com/mongodb/internal/dns/DefaultDnsResolver.java
Outdated
Show resolved
Hide resolved
@@ -83,6 +89,12 @@ public List<String> resolveHostFromSrvRecords(final String srvHost, final String | |||
for (String srvRecord : srvAttributeValues) { | |||
String[] split = srvRecord.split(" "); | |||
String resolvedHost = split[3].endsWith(".") ? split[3].substring(0, split[3].length() - 1) : split[3]; | |||
if (isShortSrvHost && resolvedHost.equals(srvHost)) { | |||
throw new MongoConfigurationException( | |||
format("The SRV host name '%s' has less than three parts and the resolved host '%s' is identical.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this (user-facing) error message discuss implementation details, for example the number of parts? The spec potentially suggests that this would be described as "...host name ... lacks a subdomain, and the resolved..."? I tried to compare against the other drivers, and I believe this corresponds to the following:
Node: https://github.com/mongodb/node-mongodb-native/pull/4197/files#diff-39b2554fd18da165b59a6351b1aafff3714e2a80c1435f2de9706355b4d32351R1181-R1185
Rust: https://github.com/mongodb/mongo-rust-driver/pull/1211/files#diff-32a39d356e1edde3d94581275b42e994ad1780ce4de8d6935ec5596fe4493ffdR39
However, I am not sure, because the error messages are different. It would have been useful if the spec specified the wording of the error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception is mainly for this prose testing case: mongodb/specifications@8e9d768#diff-dfcf948e6a987b880ea85e1907d5b7ce8fb98c9dab752f42ccdaf1e656b8848fR30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for referring to other driver's implementation. will investigate further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per the following code snippet, the exception message won't be exposed to end user but end up with a generic exception:
throw new MongoConfigurationException(format("Failed looking up SRV record for '%s'.", resourceName), e);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the logic to accommodate the possibility that 'resolvedHost' could be something like localhost
(as in Prosetest case No.3: mongodb/specifications@8e9d768#diff-dfcf948e6a987b880ea85e1907d5b7ce8fb98c9dab752f42ccdaf1e656b8848fR30) which doesn't contain '.' separator and so it has no parent domain
. After the code refactoring, no new exception or logic branch is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were the prose tests passing previously? I thought you were testing against localhost
.
exception message won't be exposed to end user
I believe all exception messages are exposed to the user. It may be in "caused by", but this is still visible.
no new exception or logic branch is required
I am not sure I follow the logic well enough to understand this - why is it that the other drivers have introduced 1 or 2 new messages, such as "Server record does not have at least one more domain level than parent URI", but we do not need to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you are totally correct in that the exception will be exposed to end user as exception's cause. I missed that. Now after new code change (converging the newly -added logic branch to the existing only flow), we reuse the old same exception mesage as below:
throw new MongoConfigurationException(
format("The SRV host name '%s' resolved to a host '%s 'that is not in a sub-domain of the SRV host.",
srvHost, resolvedHost));
It is simply another way to express the same meaning, from my understanding. Maybe it is desirable to maintain backward compatibility so I didn't change it.
...core/src/test/unit/com/mongodb/internal/connection/InitialDnsSeedListDiscoveryProseTest.java
Outdated
Show resolved
Hide resolved
...core/src/test/unit/com/mongodb/internal/connection/InitialDnsSeedListDiscoveryProseTest.java
Outdated
Show resolved
Hide resolved
...core/src/test/unit/com/mongodb/internal/connection/InitialDnsSeedListDiscoveryProseTest.java
Show resolved
Hide resolved
…redundant code comment as per code review comment
…at 'resolvedHost' might not contain '.'
9535d5d
to
fb9feb5
Compare
https://jira.mongodb.org/browse/JAVA-5542