Skip to content

Commit 523a31d

Browse files
authored
Rollup merge of rust-lang#136635 - jieyouxu:base_port, r=joboet
Remove outdated `base_port` calculation in std net test This was never modified since `std::net` was originally introduced in 395709c, when at that time, each CI runner was running multiple jobs concurrently. This seems to have originally caused issues with jobs fighting over the same ports. This is not the case in the current CI infrastructure, so remove this relic in favor of a simple constant base port number. I double-checked `19600` and nearby port numbers, and this isn't a well-known port number AFAICT[^1]. Closes rust-lang#136633. [^1]: At the time of writing.
2 parents d22ad0d + 9e345fd commit 523a31d

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

library/std/src/net/test.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToS
55
use crate::sync::atomic::{AtomicUsize, Ordering};
66

77
static PORT: AtomicUsize = AtomicUsize::new(0);
8+
const BASE_PORT: u16 = 19600;
89

910
pub fn next_test_ip4() -> SocketAddr {
10-
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
11+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
1112
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
1213
}
1314

1415
pub fn next_test_ip6() -> SocketAddr {
15-
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
16+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
1617
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
1718
}
1819

@@ -30,31 +31,3 @@ pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
3031
Err(e) => Err(e.to_string()),
3132
}
3233
}
33-
34-
// The bots run multiple builds at the same time, and these builds
35-
// all want to use ports. This function figures out which workspace
36-
// it is running in and assigns a port range based on it.
37-
fn base_port() -> u16 {
38-
let cwd = if cfg!(target_env = "sgx") {
39-
String::from("sgx")
40-
} else {
41-
env::current_dir().unwrap().into_os_string().into_string().unwrap()
42-
};
43-
let dirs = [
44-
"32-opt",
45-
"32-nopt",
46-
"musl-64-opt",
47-
"cross-opt",
48-
"64-opt",
49-
"64-nopt",
50-
"64-opt-vg",
51-
"64-debug-opt",
52-
"all-opt",
53-
"snap3",
54-
"dist",
55-
"sgx",
56-
];
57-
dirs.iter().enumerate().find(|&(_, dir)| cwd.contains(dir)).map(|p| p.0).unwrap_or(0) as u16
58-
* 1000
59-
+ 19600
60-
}

0 commit comments

Comments
 (0)