Skip to content

Commit

Permalink
fix: address already in use error in dfx start (#4006)
Browse files Browse the repository at this point in the history
* fix: address already in use error in dfx start

* unused dependency

* lint
  • Loading branch information
mraszyk authored Nov 20, 2024
1 parent ea6fd5d commit a5e8144
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 18 deletions.
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

0 comments on commit a5e8144

Please sign in to comment.