Skip to content

Commit

Permalink
Auto merge of #13907 - weihanglo:ipv6, r=ehuss
Browse files Browse the repository at this point in the history
fix: support IPv6-only network for cargo fix
  • Loading branch information
bors committed May 20, 2024
2 parents bb6e446 + ced58bf commit 3bbfe78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cargo/util/diagnostic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tracing::warn;

use crate::core::Edition;
use crate::util::errors::CargoResult;
use crate::util::network::LOCALHOST;
use crate::util::GlobalContext;

const DIAGNOSTICS_SERVER_VAR: &str = "__CARGO_FIX_DIAGNOSTICS_SERVER";
Expand Down Expand Up @@ -266,7 +267,7 @@ pub struct StartedServer {

impl RustfixDiagnosticServer {
pub fn new() -> Result<Self, Error> {
let listener = TcpListener::bind("127.0.0.1:0")
let listener = TcpListener::bind(&LOCALHOST[..])
.with_context(|| "failed to bind TCP listener to manage locking")?;
let addr = listener.local_addr()?;

Expand Down
4 changes: 3 additions & 1 deletion src/cargo/util/lockserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use std::thread::{self, JoinHandle};

use anyhow::{Context, Error};

use crate::util::network::LOCALHOST;

pub struct LockServer {
listener: TcpListener,
addr: SocketAddr,
Expand All @@ -44,7 +46,7 @@ struct ServerClient {

impl LockServer {
pub fn new() -> Result<LockServer, Error> {
let listener = TcpListener::bind("127.0.0.1:0")
let listener = TcpListener::bind(&LOCALHOST[..])
.with_context(|| "failed to bind TCP listener to manage locking")?;
let addr = listener.local_addr()?;
Ok(LockServer {
Expand Down
11 changes: 11 additions & 0 deletions src/cargo/util/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
//! Utilities for networking.

use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use std::net::SocketAddr;
use std::net::SocketAddrV4;
use std::net::SocketAddrV6;
use std::task::Poll;

pub mod http;
pub mod proxy;
pub mod retry;
pub mod sleep;

/// LOCALHOST constants for both IPv4 and IPv6.
pub const LOCALHOST: [SocketAddr; 2] = [
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0)),
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0)),
];

pub trait PollExt<T> {
fn expect(self, msg: &str) -> T;
}
Expand Down

0 comments on commit 3bbfe78

Please sign in to comment.