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

RUST-229 Parse IPv6 addresses in the connection string #1242

Merged
merged 5 commits into from
Nov 13, 2024

Conversation

isabelatkinson
Copy link
Contributor

No description provided.

@isabelatkinson isabelatkinson marked this pull request as ready for review November 12, 2024 16:16
Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM! One nit, no need for re-review.

return Ok(ServerAddress::Unix {
path: PathBuf::from(address),
});
#[cfg(unix)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already inside the #[cfg(unix)] on line 213, so I don't think this is needed.

path: PathBuf::from(address),
});
}
#[cfg(not(unix))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I don't think this will ever trigger.

@pdhanoya
Copy link

pdhanoya commented Nov 12, 2024

@isabelatkinson The changes are incorrectly parsing localhost ipv6 "mongodb://[::1]:27017"; I had to add special checks for ipv6 localhost. Please ensure [::1] and [0:0:0:0:0:0:0:1] are parsed correctly.

@isabelatkinson
Copy link
Contributor Author

The following test:

#[tokio::test]
async fn uri() {
    let uri = "mongodb://[::1]:27017";
    let options = ClientOptions::parse(uri).await.unwrap();
    dbg!("{}", options.hosts);

    let uri = "mongodb://[0:0:0:0:0:0:0:1]:27017";
    let options = ClientOptions::parse(uri).await.unwrap();
    dbg!("{}", options.hosts);
} 

gives me the following output:

[src/client/options/test.rs:369:5] "{}" = "{}"
[src/client/options/test.rs:369:5] options.hosts = [
    Tcp {
        host: "::1",
        port: Some(
            27017,
        ),
    },
]
[src/client/options/test.rs:373:5] "{}" = "{}"
[src/client/options/test.rs:373:5] options.hosts = [
    Tcp {
        host: "0:0:0:0:0:0:0:1",
        port: Some(
            27017,
        ),
    },
]

Is there a different output you're expecting?

Note that the ServerAddress::parse method only parses the "[::1]:27017" portion of the URI, so passing the entire URI to that method will fail.

@pdhanoya
Copy link

@isabelatkinson My local client fails like this when run with uri "mongodb://[::1]:27017";

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.09s
     Running `target/debug/test_client`
Error: Error { kind: InvalidArgument { message: "port must be valid 16-bit unsigned integer, instead got: " }, labels: {}, wire_version: None, source: None }```

@isabelatkinson
Copy link
Contributor Author

Based on that error message it doesn't look like you're working off the changes in the PR. What dependency do you have in your Cargo.toml file?

To test the PR changes you'll need:

mongodb = { git = "https://github.com/isabelatkinson/mongo-rust-driver", branch = "ipv6" } // plus any features you have enabled

(This is just a temporary change for testing; once we release you'll be able to depend on an official version again.)

@isabelatkinson isabelatkinson merged commit 3df0eab into mongodb:main Nov 13, 2024
14 of 17 checks passed
@pdhanoya
Copy link

@isabelatkinson I was just behind a few commits after doing a pull.. I am able to test without issue and can confirm ipv6 localhost is working as expected.

@isabelatkinson isabelatkinson deleted the ipv6 branch December 6, 2024 17:03
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.

3 participants