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

us_socket_context_connect timeout #208

Open
federicorossi opened this issue Sep 4, 2023 · 6 comments
Open

us_socket_context_connect timeout #208

federicorossi opened this issue Sep 4, 2023 · 6 comments
Labels

Comments

@federicorossi
Copy link

Can we configure the timeout of us_socket_context_connect?
Testing the code I can see it is 20s but not how to configure it or where it comes from.
It is to control the connection time when the server is down.

@uNetworkingAB
Copy link
Contributor

We don't provide any timeout. That timeout comes from the OS. You control the timeout in your OS, or use us_socket_timeout on the connecting socket.

@federicorossi
Copy link
Author

Thank you. I think that to use us_socket_timeout the us_socket_context_connect has to finish first. The problem I am facing is to control the timeout for the connect. Do you know how to change the OS timeout?

@uNetworkingAB
Copy link
Contributor

You don't need to wait. us_socket_context_connect returns a us_socket_t and you can start a timeout directly when it returns. The only thing that can take time inside us_socket_context_connect is if you pass it some domain name that doesn't resolve immediately. But you can solve that by resolving the domain to an IP yourself, before you call us_socket_context_connect.

@federicorossi
Copy link
Author

I am passing a local IP address and port that is not assigned to any device on purpose to try to limit the timeout and it takes 20s to return the socket. Is there a way to make the us_socket_context_connect to exit from another thread?

@uNetworkingAB
Copy link
Contributor

us_socket_context_connect calls some hostname resolving syscall that hangs until done. So you cannot abort it. Just make sure whatever you pass us_socket_context_connect actually resolves to something and it should return immediately. You can do this by resolving whatever you want to connect to before you pass it to us_socket_context_connect.

@federicorossi
Copy link
Author

Thank you, I will do that.
As I am passing the IP address I think the hostname resolution could be bypassed.
If you could point out what function the hostname resolution I could locally patch it.
Perhaps it could be also addressed later as an improvement to the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants