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: address already in use error in dfx start #4006

Merged
merged 3 commits into from
Nov 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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ shell-words = "1.1.0"
slog = { workspace = true, features = ["max_level_trace"] }
slog-async.workspace = true
slog-term.workspace = true
socket2 = "0.5.5"
supports-color = "2.1.0"
sysinfo = "0.28.4"
tar.workspace = true
Expand Down
17 changes: 1 addition & 16 deletions src/dfx/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use idl2json::{idl2json, Idl2JsonOptions};
use num_traits::FromPrimitive;
use reqwest::{Client, StatusCode, Url};
use rust_decimal::Decimal;
use socket2::{Domain, Socket};
use std::collections::BTreeMap;
use std::io::{stderr, stdin, stdout, IsTerminal, Read};
use std::net::{IpAddr, SocketAddr, TcpListener};
Expand All @@ -35,22 +34,8 @@ const DECIMAL_POINT: char = '.';
// thus, we need to recreate SocketAddr with the kernel-provided dynamically allocated port here.
#[context("Failed to find available socket address")]
pub fn get_reusable_socket_addr(ip: IpAddr, port: u16) -> DfxResult<SocketAddr> {
let socket = if ip.is_ipv4() {
Socket::new(Domain::IPV4, socket2::Type::STREAM, None)
.context("Failed to create IPv4 socket.")?
} else {
Socket::new(Domain::IPV6, socket2::Type::STREAM, None)
.context("Failed to create IPv6 socket.")?
};
socket
.set_linger(Some(Duration::from_secs(10)))
.context("Failed to set linger duration of tcp listener.")?;
socket
.bind(&SocketAddr::new(ip, port).into())
let listener = TcpListener::bind(SocketAddr::new(ip, port))
.with_context(|| format!("Failed to bind socket to {}:{}.", ip, port))?;
socket.listen(128).context("Failed to listen on socket.")?;

let listener: TcpListener = socket.into();
listener
.local_addr()
.context("Failed to fetch local address.")
Expand Down
Loading