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

fix: support IPv6-only network for cargo fix #13907

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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