v
v copied to clipboard
bug about socket
has been reported before, made new test script
module main
import net
fn do()?{
for i in 0 .. 10000{
println(i)
mut socket := net.dial_tcp("localhost:6379")?
}
}
fn main() {
do() or { panic(err) }
}
on osx m.1
0
1
2
3
V panic: dial_tcp failed for address localhost:6379
v hash: 5498a6c
0 redis_connect_error 0x0000000104c53b40 main__main + 100
1 redis_connect_error 0x0000000104c54d2c main + 84
2 dyld 0x0000000104df50f4 start + 520
always at the exact same iteration
has nothing to do with time, because added some sleep time (1sec even)
is to a redis server
when 127.0.0.1 went further
i've seen in other code when localhost, was different then with 127.0.0.1
Try ulimit -n 30000
, then in the same shell:
v -d net_blocking_sockets run redis_connect_error.v
on osx m.1
I don't have an m1 mac so i cant test this necessarily. From the error message it
- successfully resolves the address to something(s).
addrs := resolve_addrs_fuzzy(address, .tcp) or {
return error('$err.msg(); could not resolve address $address in dial_tcp')
}
- Goes through those addresses, creating sockets, trying to connect and failing to connect (for whatever reason, we could do with a better way of passing the why down to the end user).
for addr in addrs {
mut s := new_tcp_socket(addr.family()) or {
return error('$err.msg(); could not create new tcp socket in dial_tcp')
}
s.connect(addr) or {
// Connection failed
s.close() or { continue }
continue
}
- Returns an error because none of the sockets it created pointing to those addresses successfully connected.
}
// failed
return error('dial_tcp failed for address $address')
I think i mentioned to @medvednikov one time that it could be alignment related (given m1 is arm and not x64), however I have never been able to test this. All I know is that there is no issue with this on windows, or linux on x64
If you add a socket.close() at the end then this goes away.
module main
import net
fn do()?{
for i in 0 .. 10000{
println(i)
mut socket := net.dial_tcp("localhost:6379")?
println("Connected successfully")
socket.close()?
}
}
fn main() {
do() or { panic(err) }
}
Could I recommend closing your sockets after you have finished using them (atleast if they are still open)? My other thoughts are that it might be trying to re-use a local port for the same socket that is still open (because you havent closed it. No idea how to check that though...)