Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu marked this pull request as ready for review October 7, 2024 20:23
@NathanQingyangXu NathanQingyangXu requested review from a team and rozza and removed request for a team October 7, 2024 20:23
@NathanQingyangXu NathanQingyangXu marked this pull request as draft October 7, 2024 21:17
@NathanQingyangXu NathanQingyangXu removed the request for review from rozza October 7, 2024 21:17
Copy link
Contributor

@katcharov katcharov left a 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.

@@ -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.",
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);

Copy link
Contributor Author

@NathanQingyangXu NathanQingyangXu Oct 21, 2024

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants