Unclear TcpStream error in macOS about file limits

Hi i am New in rust. I an using standard v1.46 rust and i have a error can not fix it. please help me!

I don't know why when i use cargo run in vscode terminal It works good . but when i cargo run in mac os terminal It has error.

I discover that as long as tcpStream amount below 250 It would no error.

My code below:
url.com is example.

fn main(){
let url: Url = "http://url.com".parse().unwrap();
let url2 = url.clone();
let host = url2.host_str().unwrap();
let port = url2.port_or_known_default().unwrap();

let mut i = 0;
let mut a = Vec::new();

while i < 300 {


    let mut stream =  TcpStream::connect((host,port)).unwrap(); 



vscode output

url.com in my code just is a example. in the vscode i write an right address like google.com

Note that the server could have rate-limit that limits your connections per second.
Also it could detect DoS and ban IP address doing many connections in a short amount of time.

the problem is why when i run in vscode terminal there is no error. In macos terminal has error. This is what i feel confused.

and i am sure the ip address no rate-limit.

i tried this only happen in macos . in Linux no problem

Could you reproduce the same issue in Swift or C/C++?

I made a video you can check. I am trying to reproduce the same issue by using other language

ip address is google.com

I got answer . It because mac os' file limit is 248. this is why TcpStream connect can not more than 248

Nice. But as you said, why vscode seems to be OK ?

I check the vscode terminal by:

ulimit -a

It show me open files is 12800 but If i open New terminal outside of vscode the open files only 248. This is why rust error when TcpStream more than 248. I think vscode Give us big open files limit for developping . However in mac os system only give us open files 248 for protect system.

Yeah, that's could be the case. However I'm not a mac user so I don't have machine to check.
Even if that's the case, getting file limit should be a clearer error in Rust side ?
On Linux, after setting ulimit -n 16, I got:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 24, kind: Other, message: "Too many open files" }', src/main.rs:17:63

Could you try to set ulimit -n 16 in a new shell session and try again
to check the error message ?

Sorry i am New here so i have reply limit first day. I create a New account just now.

I tried same thing in linux. It has error but the error is 'Too many open files' rather than 'can not look up address' in mac os. Both of them In same case but the error different.

And i tried set ulimit -n 16 in a New shell session. The error messag is same : failed to lookup address information ....

I think It is wrong error messag

Moderator note: I removed the “new user” flag from your first account, which should remove some restrictions.

Cool. Could file a bug in Rust repo to report this behavior?

Thank you