You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "flip1995 (via GitHub)" <gi...@apache.org> on 2026/06/05 10:58:44 UTC

[PR] [memcached] Fix TCP address resolution [opendal]

flip1995 opened a new pull request, #7701:
URL: https://github.com/apache/opendal/pull/7701

   # 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::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.
   
   I didn't create an issue, but can do so if required. 
   
   cc @zenyanle @tisonkun 
   
   # Rationale for this change
   
   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.
   
   
   # What changes are included in this PR?
   
   Remove the additional and more restrictive `SocketAddr` parsing.
   
   # 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: 
   
   - https://github.com/mozilla/sccache/pull/2715, 
   
   which fixes a transitive GCS issue that was fixed in opendal in version 0.56.0: 
   
   - https://github.com/apache/opendal/issues/6553
   
   # AI Usage Statement
   
   I used Gemini to find the PR #7112 that introduced this change, but came up and implemented the fix myself.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4770022864

   Thanks for getting back to this quickly! Improved the comments, as you suggested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4631508398

   Both of those CI failures seem unrelated to this PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "erickguan (via GitHub)" <gi...@apache.org>.
erickguan commented on code in PR #7701:
URL: https://github.com/apache/opendal/pull/7701#discussion_r3453258236


##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]

Review Comment:
   ```suggestion
       // regression test for connecting to a webdav server.
       // Because setting up a dedicate behavior test is expensive, we choose to test `SocketStream::connect_tcp` instead.
       // In the future, we could set up a webdav server to test TCP connection properly.
       #[tokio::test]
   ```



##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]
+    async fn connect_tcp_socket() -> std::io::Result<()> {
+        // Test both ip and localhost addresses to make sure that both can be parsed.
+        for addr in &["127.0.0.1:11211", "localhost:11211", "[::1]:11211"] {
+            let listener = TcpListener::bind(addr).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)]

Review Comment:
   ```suggestion
       // regression test for connecting to a webdav server.
       // Because setting up a dedicate behavior test is expensive, we choose to test `SocketStream::connect_unix` instead.
       // In the future, we could set up a webdav server to test UNIX socket connection properly.
       #[cfg(unix)]
   ```



##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]
+    async fn connect_tcp_socket() -> std::io::Result<()> {
+        // Test both ip and localhost addresses to make sure that both can be parsed.

Review Comment:
   Please remove this comment because this test is obvious in intention and easy to understand.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on code in PR #7701:
URL: https://github.com/apache/opendal/pull/7701#discussion_r3453496119


##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]

Review Comment:
   521a915f2b940f5a25e43ba72906addd3f638c38
   



##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]
+    async fn connect_tcp_socket() -> std::io::Result<()> {
+        // Test both ip and localhost addresses to make sure that both can be parsed.
+        for addr in &["127.0.0.1:11211", "localhost:11211", "[::1]:11211"] {
+            let listener = TcpListener::bind(addr).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)]

Review Comment:
   521a915f2b940f5a25e43ba72906addd3f638c38
   



##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,56 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    #[tokio::test]
+    async fn connect_tcp_socket() -> std::io::Result<()> {
+        // Test both ip and localhost addresses to make sure that both can be parsed.

Review Comment:
   521a915f2b940f5a25e43ba72906addd3f638c38
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "erickguan (via GitHub)" <gi...@apache.org>.
erickguan merged PR #7701:
URL: https://github.com/apache/opendal/pull/7701


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on code in PR #7701:
URL: https://github.com/apache/opendal/pull/7701#discussion_r3461582940


##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,61 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    // regression test for connecting to a webdav server.
+    // Because setting up a dedicated behavior test is expensive, we choose to test `SocketStream::connect_tcp` instead.
+    // 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"] {

Review 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4667897260

   Nice, CI is passing now :tada: 
   
   Friendly ping @Xuanwo, could you take a look at this please? This is blocking a fix in `sccache` for the GCS backend.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4740277730

   Bump @Xuanwo: This is a really small 5 line PR, can you please take a look?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4768593945

   Good idea, I added regression tests for IpV4, IpV6 and the `localhost` version that was fixed by this PR, as well as the unix_socket test you suggested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "dentiny (via GitHub)" <gi...@apache.org>.
dentiny commented on code in PR #7701:
URL: https://github.com/apache/opendal/pull/7701#discussion_r3458401859


##########
core/services/memcached/src/core.rs:
##########
@@ -223,3 +219,61 @@ impl MemcachedCore {
         conn.delete(&percent_encode_path(key)).await
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use tokio::net::TcpListener;
+
+    // regression test for connecting to a webdav server.
+    // Because setting up a dedicated behavior test is expensive, we choose to test `SocketStream::connect_tcp` instead.
+    // 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"] {

Review Comment:
   I usually don't use hard-coded port number -- 11211 seems to be a well-known port number for memcached.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/memcached): TCP address resolution [opendal]

Posted by "flip1995 (via GitHub)" <gi...@apache.org>.
flip1995 commented on PR #7701:
URL: https://github.com/apache/opendal/pull/7701#issuecomment-4770636230

   Thanks for the review :pray: 
   
   Do you have a release schedule? Or are you just releasing whenever enough features/fixes have accumulated?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org