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

bug about socket #15026

Open
despiegk opened this issue Jul 11, 2022 · 5 comments
Open

bug about socket #15026

despiegk opened this issue Jul 11, 2022 · 5 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@despiegk
Copy link
Contributor

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)

@despiegk despiegk added the Bug This tag is applied to issues which reports bugs. label Jul 11, 2022
@despiegk
Copy link
Contributor Author

is to a redis server

@despiegk
Copy link
Contributor Author

image

when 127.0.0.1 went further

i've seen in other code when localhost, was different then with 127.0.0.1

@spytheman
Copy link
Member

Try ulimit -n 30000, then in the same shell:
v -d net_blocking_sockets run redis_connect_error.v

@emily33901
Copy link
Member

emily33901 commented Jul 24, 2022

on osx m.1

I don't have an m1 mac so i cant test this necessarily. From the error message it

  1. 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')
  }
  1. 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
  	}
  1. 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

@emily33901
Copy link
Member

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...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

3 participants