TcpListener::bind alwary success though specific port already occupied
Please provide steps to reproduce or an overview over the bound sockets after this happens. There are enough complications about multiple network interfaces, IP addresses etc. that it's not obvious what could be the issue here.
The following example can reproduce this issue, this program can still running though i see this addr was already occupied
When i impl this example by golang (or another programming language), it can not work in port-occupied situation
listener, err := net.Listen("tcp", "0.0.0.0:35628")
if err != nil {
fmt.Println("Error creating listener:", err)
os.Exit(1)
}
defer listener.Close()
For me, your example fails as expected with:
Error: Os { code: 98, kind: AddrInUse, message: "Address already in use" }
strace (or equivalent on whatever platform we're talking about) output would be informative.
For me, your example fails as expected with:
Error: Os { code: 98, kind: AddrInUse, message: "Address already in use" }strace (or equivalent on whatever platform we're talking about) output would be informative.
When i run this example to occupy this addr, another example can no use this address and raise the above error ( which is expected), but when this addr was occupied by another (no example code) process (like ssh 127.0.0.1:22 or even port 127.0.0.1:1 ), this addr can be use by this example (wire)
I think you're observing the effect that https://github.com/rust-lang/rust/blob/748c54848dc2964b7e133f945cabe5bc64079947/library/std/src/sys_common/net.rs#L403-L411 achieves.
But SO_REUSEADDR does not allow binding if there is an active listening socket elsewhere, so some of your description is still confusing.