fix(services/memcached): TCP address resolution#7701
Conversation
|
Both of those CI failures seem unrelated to this PR. |
38488ef to
8f7ee39
Compare
PR apache#7112 added support for Unix sockets to the memcached backend. As a side effect, it switched the TCP address parsing from being done inside of `TcpStream::connect` to `SocketAddr::parse`. The major difference is that `SocketAddr::parse` cannot resolve addresses like `localhost:1234`, as it errors out if it sees non-octal numbers in the address. This seemed like an unintended breaking change to me. I also can't see the benefit of doing that, as `TcpStream::connect` already calls `to_socket_addrs` internally.
8f7ee39 to
0cfaa3c
Compare
|
Nice, CI is passing now 🎉 Friendly ping @Xuanwo, could you take a look at this please? This is blocking a fix in |
|
Bump @Xuanwo: This is a really small 5 line PR, can you please take a look? |
erickguan
left a comment
There was a problem hiding this comment.
Looks good. Can we add regression tests?
Something similar to:
#[cfg(test)]
mod tests {
use super::*;
use tokio::net::TcpListener;
#[tokio::test]
async fn connect_tcp_socket() -> std::io::Result<()> {
# test a few other use cases
let listener = TcpListener::bind("127.0.0.1:0").await?;
let addr = listener.local_addr()?.to_string();
let accepted = tokio::spawn(async move {
let _ = listener.accept().await?;
Ok::<_, std::io::Error>(())
});
let _stream = SocketStream::connect_tcp(&addr).await?;
accepted.await.unwrap()?;
Ok(())
}
#[cfg(unix)]
#[tokio::test]
async fn connect_unix_socket() -> std::io::Result<()> {
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::net::UnixListener;
# can use tempfile instead.
let path = std::env::temp_dir().join(format!(
"opendal-memcached-{}.sock",
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos()
));
let listener = UnixListener::bind(&path)?;
let accepted = tokio::spawn(async move {
let _ = listener.accept().await?;
Ok::<_, std::io::Error>(())
});
let _stream = SocketStream::connect_unix(path.to_str().unwrap()).await?;
accepted.await.unwrap()?;
let _ = std::fs::remove_file(path);
Ok(())
}
}|
Good idea, I added regression tests for IpV4, IpV6 and the There's no direct dependency on tempfile yet, so I used the |
erickguan
left a comment
There was a problem hiding this comment.
Some final comment updates and we are good to go!
|
Thanks for getting back to this quickly! Improved the comments, as you suggested. |
|
Thanks for the review 🙏 Do you have a release schedule? Or are you just releasing whenever enough features/fixes have accumulated? |
| // In the future, we could set up a webdav server to test TCP connection properly. | ||
| #[tokio::test] | ||
| async fn connect_tcp_socket() -> std::io::Result<()> { | ||
| for addr in &["127.0.0.1:11211", "localhost:11211", "[::1]:11211"] { |
There was a problem hiding this comment.
I usually don't use hard-coded port number -- 11211 seems to be a well-known port number for memcached.
There was a problem hiding this comment.
I think this is fine in a test case. And all other tests I saw here and in sccache use the hard-coded 11211 port number.
Which issue does this PR close?
PR #7112 added support for Unix sockets to the memcached backend. As a side effect, it switched the TCP address parsing from being done inside of
TcpStream::connecttoSocketAddr::parse. The major difference is thatSocketAddr::parsecannot resolve addresses likelocalhost:1234, as it errors out if it sees non-octal numbers in the address.I didn't create an issue, but can do so if required.
cc @zenyanle @tisonkun
Rationale for this change
#7112 claimed:
But it broke TCP configurations like
tcp://localhost:11211.So, this seemed like an unintended breaking change to me. I also can't see the benefit of doing that, as
TcpStream::connectalready callsto_socket_addrsinternally.What changes are included in this PR?
Remove the additional and more restrictive
SocketAddrparsing.Are there any user-facing changes?
This restores the behavior from before the 0.56.0 release. This is required to bump the opendal dependency in
sccache:which fixes a transitive GCS issue that was fixed in opendal in version 0.56.0:
AI Usage Statement
I used Gemini to find the PR #7112 that introduced this change, but came up and implemented the fix myself.